简体   繁体   中英

CSS Print Preview Margins

I am trying to set the size of margins on a page in the Internet Explorer 11 Print Preview. I am also trying to clear the margins of any content (ex. page numbers, titles, urls etc.)

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.

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. I didn't think to check browser support. Now I see that they are not supported in most browsers (see Margin boxes support .)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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