简体   繁体   English

在打印时,如何在 CSS 页面上重复页眉和页脚横幅?

[英]On print, how do I repeat header and footer banners on pages in CSS?

My banners are divs and this what the HTML looks like:我的横幅是 div,这是 HTML 的样子:

<div class="top-banner">
  UNCLASSIFIED
</div>

<table class="print-section">
  <thead>
    <tr>...</th
      <th>...</th
      <th>...</th
    <tr>...</th
  </thead>

  <tbody>
    <tr>
      <td>...</td>
      <td>...</td>
    </tr> 
  </tbody>

</table>

<div class="bottom-banner">
  UNCLASSIFIED
</div>

CSS Style Sheet looks like this: CSS 样式表如下所示:

@media print {
 .print-section {
   display: table;
   overflow: visible;
 }

 .top-banner, .bottom-banner {
  display: block;
  width: 100%;
  color: green;
 }
}

Problem: Only the bottom banner shows at the end of page when the table breaks into another page on print.问题:当表格在打印时分成另一页时,页面末尾仅显示底部横幅。 How do I fix this?我该如何解决?

If you add this to your @media print CSS it should show the banners on each printed page.如果您将此添加到您的 @media 打印 CSS,它应该在每个打印页面上显示横幅。 You will probably want to look at margins too depending on what you are printing to.根据您要打印的内容,您可能还想查看边距。

  .bottom-banner {
    position: fixed;
    bottom: 0;
  }
   .top-banner {
    position: fixed;
    top: 0;
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM