如何使用 HTML 在文档的每个打印页面上打印页眉和页脚? [英] How to use HTML to print header and footer on every printed page of a document?
问题描述
是否可以在每个打印页面上打印带有自定义页眉和页脚的 HTML 页面?
Is it possible to print HTML pages with custom headers and footers on each printed page?
无论内容如何,我想在每个打印页面的顶部和底部添加红色、Arial、大小为 16pt 的UNCLASSIFIED"字样.
I'd like to add the word "UNCLASSIFIED" in Red, Arial, size 16pt to the top and bottom of every printed page, regardless of the content.
澄清一下,如果文档打印在 5 页上,每页都应该有自定义页眉和页脚.
To clarify, if the document was printed onto 5 pages, each page should have the custom header and footer.
有人知道这是否可以使用 HTML/CSS 实现?
Does anybody know if this is possible using HTML/CSS?
推荐答案
如果你把想要作为页脚的元素设置为 position:fixed 和 bottom:0,页面打印时会重复每个打印页面底部的元素.这同样适用于标题元素,只需设置 top:0.
If you take the element that you want to be the footer and set it to be position:fixed and bottom:0, when the page prints it will repeat that element at the bottom of each printed page. The same would work for a header element, just set top:0 instead.
例如:
<div class="divFooter">UNCLASSIFIED</div>
CSS:
@media screen {
div.divFooter {
display: none;
}
}
@media print {
div.divFooter {
position: fixed;
bottom: 0;
}
}
这篇关于如何使用 HTML 在文档的每个打印页面上打印页眉和页脚?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!