我可以在 HTML 打印中强制分页吗? [英] Can I force a page break in HTML printing?
问题描述
我正在制作一个可打印的 HTML 报告,它有部分",应该从一个新页面开始.
有没有什么办法可以在 HTML/CSS 中放入一些东西来通知浏览器它此时需要强制分页(开始一个新页面)?
我不需要它在所有浏览器中都能运行,我想我可以告诉人们使用一组特定的浏览器来打印它.
添加一个名为pagebreak"(或pb")的 CSS 类,如下所示:
@media print {.pagebreak { page-break-before: 总是;}/* page-break-after 工作,以及 */}
然后添加一个空的 DIV 标签(或任何块元素生成一个框),您希望在其中分页.
不会出现在页面上,但是打印的时候会分页.
附言也许这仅适用于使用 -after
时(以及您可能对页面上的其他 <div>
执行的其他操作),但我发现我必须按如下方式扩充 CSS 类:
@media print {.分页符 {清楚:两者;分页后:总是;}}
I'm making a HTML report that is going to be printable, and it has "sections" that should start in a new page.
Is there any way to put something in the HTML/CSS that will signal to the browser that it needs to force a page break (start a new page) at that point?
I don't need this to work in every browser out there, I think I can tell people to use a specific set of browsers in order to print this.
Add a CSS class called "pagebreak" (or "pb"), like so:
@media print {
.pagebreak { page-break-before: always; } /* page-break-after works, as well */
}
Then add an empty DIV tag (or any block element that generates a box) where you want the page break.
<div class="pagebreak"> </div>
It won't show up on the page, but will break up the page when printing.
P.S. Perhaps this only applies when using -after
(and also what else you might be doing with other <div>
s on the page), but I found that I had to augment the CSS class as follows:
@media print {
.pagebreak {
clear: both;
page-break-after: always;
}
}
这篇关于我可以在 HTML 打印中强制分页吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!