我正在制作一个HTML报告,该报告将是可打印的,并且其中的小节"应在新页面中开始.
I'm making a HTML report that is going to be printable, and it has "sections" that should start in a new page.
是否有任何方法可以在HTML/CSS中放置一些内容,以告知浏览器此时需要强制分页(启动新页面)?
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.
推荐答案添加一个名为"pagebreak"(或"pb")的CSS类,如下所示:
Add a CSS class called "pagebreak" (or "pb"), like so:
@media print { .pagebreak { page-break-before: always; } /* page-break-after works, as well */ }然后添加一个空的DIV标记(或任何阻止元素会在想要分页的位置生成一个框).
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.也许这仅适用于使用-after的情况(以及页面上其他<div>的其他用途),但是我发现我必须按如下方式扩充CSS类:
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打印中强制分页吗?
发布评论