[英]How to set margin top, bottom of page in print?
I want to print a special div of page with javascript. 我想用JavaScript打印页面的特殊div。
<script language="javascript">
function printDiv(divName) {
var printContents = document.getElementById(divName).innerHTML;
var originalContents = document.body.innerHTML;
document.body.innerHTML = printContents;
window.print();
document.body.innerHTML = originalContents;
}
</script>
and in html page 并在html页面中
<div id="MainDIV" style="width:700px; min-height: 100%; padding-top: 0; margin-top: 0; padding-right:15px; padding-left: 15px;font-family: 'BYagut' !important">
// my code
</div>
and set css for this page. 并为此页面设置css。
@page {
margin-top: 0;
margin-bottom: 0;
}
but when I click the print button, there is a large distance from the top of the page. 但是当我单击打印按钮时,距页面顶部的距离很大。
Check out @media . 查看@media 。 You can set it to "print" and specify the margins in your CSS.
您可以将其设置为“ print”,并在CSS中指定页边距。
The @media CSS at-rule lets you specify declarations that depend on the condition of a media query.
@media CSS规则可让您指定依赖于媒体查询条件的声明。 The rule may be placed at the top level of your code or nested inside any other conditional group at-rule.
该规则可以放在代码的顶层,也可以嵌套在任何其他条件组规则中。
打印
Intended for paged material and for documents viewed on screen in print preview mode.
适用于分页材料和在打印预览模式下在屏幕上查看的文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.