Firefox print CSS - Extra blank page on A4 page

Deviling Master picture Deviling Master · May 31, 2015 · Viewed 7.4k times · Source

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?

Answer

Julian Xhokaxhiu picture Julian Xhokaxhiu · May 31, 2015

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>