我可以在HTML打印中强制分页吗?

编程入门 行业动态 更新时间:2024-10-15 06:13:21
本文介绍了我可以在HTML打印中强制分页吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在制作一个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打印中强制分页吗?

本文发布于:2023-10-31 13:49:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546272.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:分页   HTML

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!