如何解决分页闯入的替代方法:避免
| 我有一个生成优惠券的页面。每个优惠券均为a0ѭ,高度随内容而变化。我想在每页上打印尽可能多的优惠券,但我不希望将优惠券分成几页。 CSS属性page-break-inside
正是我所需要的。但是,我需要它才能用于Firefox和/或Chrome。并且不支持此功能。两年零一年以前,有人问过同样的问题,没有别的好选择。我们正在进一步开发CSS3 / HTML5 /整体浏览器...是否有替代方法可以使此功能正常工作?
示例在这里:
http://jsfiddle.net/e3U66/2/
假设页面在打印时尺寸为1000像素。我希望第二个DIV出现在第二页上,因为否则它将分为第一页和第二页。此代码可在Opera中使用,但不能在FF或Chrome中使用。
解决方法
为什么不呢,在页面上加载了内容之后,请使用js滚动浏览内容并增加ѭ0的高度。
达到
1000px
或确定为页面高度后,请在最新的div之前插入以page-break-before
样式的空白div
。
,下面是借助Prototype(1.7)库制作的解决方案
<!DOCTYPE HTML>
<html>
<head>
<title>Title of the document</title>
<script type=\"text/javascript\" src=\"js/prototype.js\"></script>
<script type=\"text/javascript\">
//page height in px
//thisPageTotal is the total of pixels on the current page,in px
pageHeight = 1000;
thisPageTotal = 0;
Event.observe(window,\'load\',function(){
$$(\'.coupon\').each(function(el){
var layout = el.getLayout();
thisPageTotal += parseInt(layout.get(\'margin-box-height\'));
if(thisPageTotal > pageHeight) {
thisPageTotal = parseInt(layout.get(\'margin-box-height\'));
var pageBreak = new Element(\'div\',{
\'class\': \'pagebreak\'
});
el.insert({before: pageBreak});
}
//this shows the current amount of px on the current page
el.update(thisPageTotal);
});
});
</script>
<style type=\"text/css\">
div {
border: 1px solid #000;
margin: 30px;
}
.pagebreak {
page-break-after: always;
}
</style>
</head>
<body>
<div id=\"div_1\" class=\"coupon\" style=\"height: 500px\"></div>
<div id=\"div_2\" class=\"coupon\" style=\"height: 200px\"></div>
<div id=\"div_3\" class=\"coupon\" style=\"height: 500px\"></div>
<div id=\"div_4\" class=\"coupon\" style=\"height: 200px\"></div>
<div id=\"div_5\" class=\"coupon\" style=\"height: 200px\"></div>
<div id=\"div_6\" class=\"coupon\" style=\"height: 400px\"></div>
<div id=\"div_7\" class=\"coupon\" style=\"height: 300px\"></div>
<div id=\"div_8\" class=\"coupon\" style=\"height: 400px\"></div>
<div id=\"div_9\" class=\"coupon\" style=\"height: 500px\"></div>
<div id=\"div_10\" class=\"coupon\" style=\"height: 200px\"></div>
</body>
</html>
也许有帮助
,老实说,我只建议创建实际优惠券的图像或生成pdf。我假设您可能已经在为所有优惠券生成条形码,因此使用php(或任何代码选择可能)都不应该很难生成实际的图像。
这是有关php映像创建的一些信息,但是SO可能是示例的更好来源。
http://php.net/manual/zh/function.imagecreate.php
然后,您可以只列出图像。
<img src>
<img src>
<img src>
...
没有任何意义可以重塑车轮。
,将这些div的左侧浮动,并将宽度设置为100%。
我不会尝试的。,它可能会工作。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。