在所有页面上打印页眉/页脚(打印模式)
<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>
我想在打印模式下在每一页上打印#header
和#footer
。我搜索了很多,但似乎没有任何效果,甚至 position:fixed
也没有按预期工作。
<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>
I want to print #header
and #footer
on every page in print mode. I searched a lot but nothing seems to work, even position:fixed
doesn't work as expected.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您愿意根据自己的布局切换到表格(不一定理想),则可以使用
和
元素来实现。它们将打印在每个页面的顶部和底部:
另一种选择是使用显示
table-header-group
和table-footer-group
但跨浏览器支持不支持不太好:If you're willing to switch over to tables for your layout (not necessarily ideal), you can do it with the
<thead>
and<tfoot>
elements. They'll print at the top and bottom of every page:Another option is to use display
table-header-group
andtable-footer-group
but cross-browser support isn't great:我想我来得太晚了:),但我一直在寻找这样的东西,我找到了一个对我有帮助的答案(来源https://www.youtube.com/watch?v=yDgFLysON98)。
我在内容之前和之后编写了 div 标签,如下所示
示例:
...我希望这会有所帮助。
I think I arrived too late :), but I was looking for something like this, and I found one answer that helps me (source https://www.youtube.com/watch?v=yDgFLysON98).
I wrote the div tag before and after the content like this
Example:
... I hope this helps.
为此,您需要在您的样式中使用 mso(microsoft office css 属性):
For that you need to use the mso (microsoft office css properties) in your style:
Nisse Engstroms 的答案是正确的。你只需要把 thead 和 tfoot 内容放在 tr 中就可以了。这也是最好的方法,因为当你在 div 中使用绝对定位来制作页眉和页脚时,它总是会与你的主体内容重叠下一页。
Nisse Engstroms answer is correct. You just need to put the thead and tfoot content inside a tr to make it work.And it also is the best method because when you use absolute positioning in a div to make header and footer it will always overlap with your main body content on the next page.