打印时防止 HTML 元素跨越多个页面
我有以下 HTML,我希望在跨多个页面时不被破坏。问题是,如果我在之前或之后使用分页符,它将把每个元素放在它自己的页面上。我遇到的另一个问题是,如果我在 cell
CSS 类或 wrap
类上设置 display: block
,则 DIV 或LI还是分手了。我有一个印刷媒体 CSS 文件和一个屏幕 CSS 文件。我想防止
元素及其内容被破坏。 <div class="pad">
<h1 style="text-align: center; margin: 10px 0">
Work Orders for Jan 05, 2011
</h1>
<p class="printHidden">
<a href="/orders/print-all/date/2011-01-05">Print All Work Orders</a>
</p>
<ul class="workorders">
<li class="cell">
<div class="wrap" id="146">
<div class="scheduled">
<p>
<strong>Work Order:</strong> <a href="/orders/view/work-order/146">158801</a>
</p>
<p>
<strong>Client:</strong> Client Name
</p><br>
<b>Resources</b>
<ul>
<li>
<a href="/resources/view/resource-id/5" id="Person-5">Mikell McLaindon</a>
</li>
<li>
<a href="/resources/view/resource-id/9" id="Person-9">Jose Copper</a>
</li>
</ul>
</div>
<div class="unschedule printHidden">
<h1 style="text-align: center; margin: 10px 0 10px; font-size: 12px; font-weight: bold;">
Unschedule Resource for 15880-PW
</h1>
</div>
</div>
</li>
{... removed for brevity ...}
I have the following HTML that I would like to keep from being broken up when spanning multiple pages. The problem is that if I use page-break-before or after, it will put each element on it's own page. The other problem I'm having is that if I set display: block
on either the cell
CSS class or the wrap
class, the DIV or LI still gets broken up. I have a print media CSS file and a CSS file for the screen as well. I want to keep the <li class="cell">
element and its contents from being broken up.
<div class="pad">
<h1 style="text-align: center; margin: 10px 0">
Work Orders for Jan 05, 2011
</h1>
<p class="printHidden">
<a href="/orders/print-all/date/2011-01-05">Print All Work Orders</a>
</p>
<ul class="workorders">
<li class="cell">
<div class="wrap" id="146">
<div class="scheduled">
<p>
<strong>Work Order:</strong> <a href="/orders/view/work-order/146">158801</a>
</p>
<p>
<strong>Client:</strong> Client Name
</p><br>
<b>Resources</b>
<ul>
<li>
<a href="/resources/view/resource-id/5" id="Person-5">Mikell McLaindon</a>
</li>
<li>
<a href="/resources/view/resource-id/9" id="Person-9">Jose Copper</a>
</li>
</ul>
</div>
<div class="unschedule printHidden">
<h1 style="text-align: center; margin: 10px 0 10px; font-size: 12px; font-weight: bold;">
Unschedule Resource for 15880-PW
</h1>
</div>
</div>
</li>
{... removed for brevity ...}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:正确的解决方案
请参阅:http://www.w3schools.com/ css/pr_print_pagebi.asp
因此,如果您将以下内容添加到 CSS 中,它应该可以解决您的问题:
所有主要的桌面浏览器现在都支持此功能。
不过,还有
page-break-after:avoid
和page-break-before:avoid
,您可以将它们添加到中的每个元素。 pad
类,以便在某些旧版本的浏览器中产生相同的结果。http://www.w3schools.com/Css/pr_print_pagebb.asp
http://www.w3schools.com/css/pr_print_pageba.asp
旧答案:
好像您正在尝试将不适合页面的内容放入页面中。我会尝试添加一个带有
media="print"
... 的样式表,以减少所有这些元素的字体大小、填充等,以便您可以在此之前添加分页符部分并使其适合页面。
EDIT: PROPER SOLUTION
See: http://www.w3schools.com/css/pr_print_pagebi.asp
So if you add the following to your CSS it should fix your problem:
All the major desktop browsers now support this.
However, there is also
page-break-after:avoid
andpage-break-before:avoid
which you can add to every element within the.pad
class in order to produce the same result in some older versions of browsers.http://www.w3schools.com/Css/pr_print_pagebb.asp
http://www.w3schools.com/css/pr_print_pageba.asp
OLD ANSWER:
It sounds like you're trying to fit something on a page that doesn't fit on a page. I would try adding a stylesheet with
media="print"
......that reduces the font size, padding, etc. of all of these elements so that you CAN put a page break before this section and have it fit on the page.