当我尝试打印网页时,为什么每个打印页面都没有重复内容?

问题描述 投票:7回答:4

我有一张桌子,我正在尝试打印它。它在正常模式下工作正常,但是当我旋转我的th时,它在第一个打印页面中可见,但在其他页面上不可见。

th span {
  transform-origin: 0 50%;
  transform: rotate(-90deg);
  white-space: nowrap;
  display: block;
  position: relative;
  top: 0;
  left: 50%;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" integrity="sha384-Smlep5jCw/wG7hdkwQ/Z5nLIefveQRIY9nfy6xoR1uRYBtpZgI6339F5dgvm/e9B" crossorigin="anonymous">

<table class="table table-bordered">
  <thead>
    <tr>
      <th><span style="transform-origin: 0 50%;
        transform: rotate(-90deg);
        white-space: nowrap;
        display: block;
        position: relative;
        top: 0;
        left: 50%;">Firstname</span></th>
      <th>Lastname</th>
      <th>Email</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>John</td>
      <td>Doe</td>
      <td>[email protected]</td>
    </tr>
    <tr>
      <td>Mary</td>
      <td>Moe</td>
      <td>[email protected]</td>
    </tr>
    <tr>
      <td>July</td>
      <td>Dooley</td>
      <td>[email protected]</td>
    </tr>

    <tr>
      <td>Mary</td>
      <td>Moe</td>
      <td>[email protected]</td>
    </tr>
    <tr>
      <td>July</td>
      <td>Dooley</td>
      <td>[email protected]</td>
    </tr>
    <tr>
      <td>John</td>
      <td>Doe</td>
      <td>[email protected]</td>
    </tr>
    <tr>
      <td>Mary</td>
      <td>Moe</td>
      <td>[email protected]</td>
    </tr>
    <tr>
      <td>July</td>
      <td>Dooley</td>
      <td>[email protected]</td>
    </tr>
  </tbody>
</table>

第一和第二个打印页面的屏幕截图:

首页打印页面:

enter image description here

第二页打印:

enter image description here

注意:当我从span中删除旋转th时,这是有效的

缺什么?

javascript jquery html css printing
4个回答
8
投票

有些浏览器会像每个页面那样重复每个页面上的thead元素。但是有些浏览器不会,你需要为你的表头添加额外的css

thead {display: table-header-group;}

注意:无论您尝试什么,Opera 7.5和IE 5都不会重复标题。


2
投票

对于打印,您可以使用单独的CSS。

在下面的打印介质中添加代码。

@media print {

    // Your code here

}

希望它会奏效。


2
投票

我得到了我的答案它现在已修复并正常工作,因为现在我在打印脚本代码中使用CSS而不是普通的CSS。


-1
投票

你可能需要给你的th一些填充

th {
    padding: 3em;
}

What my print looks like after I add padding to th

© www.soinside.com 2019 - 2024. All rights reserved.