Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.8k views
in Technique[技术] by (71.8m points)

js调用window.print()打印页面的时候 怎么给打印的每一页都加上logo做背景图

公司有个需求打印一些公司的合同的时候要给每一页添加一个logo之前采用的办法是给页面添加多个img然后设置绝对定位top值现在发现打印出来有时候后面几页没有图片 怎么才能获取到这个网页打印的总页数呢 之前用的办法有问题


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

@media print 用这个来设置CSS打印属性

——————

test.html

<!DOCTYPE html>
<head>
  <style>
    .background {
      position: fixed;
      left: 0;
      right: 0;
      top: 0;
      bottom: 0;
      z-index: -1;
      background: url(https://cdn.colorhub.me/imgsrv/9957a1bfc45d18ef09645dff1352cf7bab011fee);
      background-position: center center;
      background-repeat: no-repeat;
      display: none;
    }

    .content {
      padding: 600px 0;
      text-align: center;
      font-size: 50px;
      color: red;
    }

    @media print {
      .background {
        display: block;
      }
    }
  </style>
</head>

<body>
  <div class="background"></div>
  <div class="main">
    <div class="content">
      第1部分
    </div>
    <div class="content">
      第2部分
    </div>
    <div class="content">
      第3部分
    </div>
    <div class="content">
      第4部分
    </div>
  </div>
</body>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...