简体   繁体   English

CSS打印预览边距

[英]CSS Print Preview Margins

I am trying to set the size of margins on a page in the Internet Explorer 11 Print Preview. 我正在尝试在Internet Explorer 11的“打印预览”中设置页边距的大小。 I am also trying to clear the margins of any content (ex. page numbers, titles, urls etc.) 我也在尝试清除任何内容(例如页码,标题,URL等)的空白

I have managed to set the margin size, but I cannot get the content to clear. 我已经成功设置了边距大小,但是无法清除内容。 Here is my code: Could anyone spot something that I am doing wrong? 这是我的代码:有人可以发现我做错了什么吗? Once I have it working for the top margin, I can replicate the fix to the rest. 一旦它为最高利润而工作,我就可以将修复程序复制到其余部分。

<!DOCTYPE HTML>
<html>
<head>
<title>Print Test</title>       

<style type="text/css">

@page {
    margin-top: 50mm;
    margin-bottom: 50mm;
    margin-left: 50mm;
    margin-right: 50mm;

    @top-left-corner {content: none}
    @top-left {content: none}
    @top-center {content: none}
    @top-right {content: none}
    @top-right-corner {content: none}    
}

</style>    
</head>
<body>
    <h1>Header Here</h1>
    <p>
        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    </p>
</body>
</html>

The only thing that comes to mind is that :first, :blank, :left, and :right specifiers have higher level specificity than just @page by itself. 唯一想到的是:first,:blank,:left和:right指示符比@page本身具有更高的级别特异性。

Try this to override them all: 尝试执行以下操作以覆盖所有内容:

@page, @page :first, @page :right, @page :left, @page :blank {
    @top-left-corner {content: none}
    @top-left {content: none}
    @top-center {content: none}
    @top-right {content: none}
    @top-right-corner {content: none}  
}

Update: I spend most of my time rendering in PrinceXML. 更新:我大部分时间都花在PrinceXML中。 I didn't think to check browser support. 我没想到要检查浏览器支持。 Now I see that they are not supported in most browsers (see Margin boxes support .) 现在,我发现大多数浏览器均不支持它们(请参阅边距框支持)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM