在所有页面上打印页眉/页脚(打印模式)

3zz*_*zzy 24 html css printing fixed repeat

<div id="header">header</div>
<div id="content">
    content spanning several pages...
</div>
<div id="footer">Footer - Fixed at the bottom of each page</div>
Run Code Online (Sandbox Code Playgroud)

我想打印#header#footer每个打印模式页.我搜索了很多,但似乎没有任何工作,甚至position:fixed没有按预期工作.

Pat*_*Pat 24

如果您愿意切换到布局的表格(不一定是理想的),您可以使用<thead><tfoot>元素来完成.它们将打印在每页的顶部和底部:

<table>

  <thead>
     <!-- Will print at the top of every page -->
  </thead>

  <tbody>
     <!-- Page content -->
  </tbody>

  <tfoot>
     <!-- Will print at the bottom of every page -->
  </tfoot>

</table>
Run Code Online (Sandbox Code Playgroud)

另一个选择是使用显示table-header-group,table-footer-group但跨浏览器支持不是很好:

#header {
  display: table-header-group;
}

#main {
  display: table-row-group;
}

#footer {
  display: table-footer-group;
}
Run Code Online (Sandbox Code Playgroud)

  • 在Chrome/Safari中不起作用,不管怎么说? (4认同)
  • 2016年仍然没有运气与铬/野生动物园! (3认同)
  • __2017__仍然__在Chrome中不起作用!__ _但两种方法都适用于Firefox_ (3认同)
  • 这似乎是唯一的解决方案,它只适用于IE/Firefox.对于Chrome,Safari或Opera而言,就我所知(和研究)而言,没有解决方案. (2认同)
  • 2019 年 12 月:这是一个很好的答案,只要在“#header”和“#footer”中添加“page-break-before:void;”,table-header-group hack 在 Chrome 中就可以正常工作。 .根据https://bugs.chromium.org/p/chromium/issues/detail?id=24826#c42 (2认同)