Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Empty body element with exact A4 landscape dimension is printed on 2 pages

Tags:

html

css

printing

Demo:

print()
@page {
    size: A4 landscape;
    margin: 0;
}
html, body {
    margin: 0;                
}
html {
    background: cyan;
}
body {
    width: 297mm;
    height: 210mm;                
    background: red;
}

The dimensions for A4 landscape are correct, but the print overflows to the second page. These happens in Win 10 Chrome 63, FF 52 and Edge 41.

enter image description here

When I use the portrait dimensions and print A4 Portrait, then only one page is printed as expected, without any overflow.

Does anybody have any clues to this issue? Does it occur on every platform?

Thank you in advance

like image 245
tenbits Avatar asked Jan 18 '18 12:01

tenbits


1 Answers

used body {margin-top: -1px }

print()
@page {
    size: A4 landscape;
    margin: 0;
}
html, body {
    margin: 0;      
}
html {
    background: cyan;
}
body {
    width: 297mm;
    height: 210mm;     
    background: red;
    margin-top: -1px;
}
like image 75
Farhad Bagherlo Avatar answered Sep 26 '22 15:09

Farhad Bagherlo