我使用的是CSS属性,
如果我使用page-break-after: always;
=>,它会打印一个额外的空白页
如果我使用page-break-before: always;
=>,它会在之后打印额外的空白页。如何避免这种情况?
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style type="text/css">
.print{
page-break-after: always;
}
</style>
<script type="text/javascript">
window.print();
</script>
</head>
<body>
<div class="print">fd</div>
<div class="print">fdfd</div>
</body>
</html>
发布于 2011-10-21 17:11:18
你也许可以添加
.print:last-child {
page-break-after: auto;
}
因此,最后一个print
元素将不会获得额外的分页符。
请注意,如果您针对的是一个可恶的浏览器,那么在IE8中不支持:last-child选择器。
发布于 2013-10-23 07:02:04
你试过这个吗?
@media print {
html, body {
height: 99%;
}
}
发布于 2014-06-19 18:16:47
描述的解决方案here帮助了我(webarchive link)。
首先,您可以向所有元素添加边框,以查看是什么导致添加新页面(可能是一些页边距、填充等)。
div { border: 1px solid black;}
而解决方案本身就是添加以下样式:
html, body { height: auto; }
https://stackoverflow.com/questions/7846346
复制相似问题