Firefox print CSS - Extra blank page on A4 page
Asked Answered
W

1

8

I created a simple print CSS which generates an A4 page.

<!doctype html>
<html>
<head>
<style media="print">
    * {margin:0;padding:0}
    @page {size: 297mm 210mm; margin:0mm;}
    html, body {width: 297mm; height: 210mm}
    html {background-color:red}
    body {background-color:green}
</style>
</head>

<body>
    <p>TEST</p>
</body>
</html>

With Firefox 38.0.1, in the Print Preview window, the body (green colored) has an extra height which triggers a second page firefox

If I print the file, 2 pages are printed, so it is not a problem related only to the print preview.

I already removed all the margins from the Page Setup section and all the extra elements which Firefox adds (like title, url, date, ...)

The same page on Chrome 43.0.2357.81 does not have any problem chrome

How can i solve that?

Waldrup answered 31/5, 2015 at 10:55 Comment(0)
P
14

Use this, it will work straight forward :)

<!doctype html>
<html>
    <head>
        <style>
            @media print {
                * {margin:0;padding:0}
                @page {size: A4 landscape; margin:0mm;}
                html, body {height: 100%;}
                html {background-color:red}
                body {background-color:green}
            }
        </style>
    </head>
    <body>
        <p>TEST</p>
    </body>
</html>
Pharisaism answered 31/5, 2015 at 12:0 Comment(3)
@DevilingMaster please accept this answer. This worked for me as well :)Fourscore
Perfect, the only solution ever to work for me. Thank youHathaway
@julian-xhokaxhiu Thank you, saved me more headaches!Hypertensive

© 2022 - 2024 — McMap. All rights reserved.