I searched a lot before asking here, but didn't find an answer for my question.
I want to insert top and bottom margin for my website page when printed, so I used the normal margin-top
and margin-bottom
for the printed div but it affected on the first sheet only! so I used this as explained in W3C CSS2.1 Specifiction:
@page {
margin-top: 5cm;
margin-bottom: 5cm;
}
but no effect in Firefox Print Preview or Print to PDF. so how can I insert top and bottom margin (for each printed sheet) via CSS? or is there any trick to do this in Firefox?
The dimensions of the page box are set with the 'size' property. The dimensions of the page area are the dimensions of the page box minus the margin area. You can use the margin, margin-top, margin-bottom, margin-left, and margin-right properties within the @page rule to set margins for your page.
For best results, print within the recommended printable area. The printer may not print outside this area. The minimum top margin is 4.2 mm (0.17 inch). The minimum left and right margins are 3.0 mm (0.12 inch) each.
You can use CSS to change the appearance of your web page when it's printed on a paper. You can specify one font for the screen version and another for the print version. You have seen @media rule in previous chapters. This rule allows you to specify different style for different media.
Both
@page {
margin-top: 5cm;
margin-bottom: 5cm;
}
and
@media print {
body {margin-top: 50mm; margin-bottom: 50mm;
margin-left: 0mm; margin-right: 0mm}
}
work fine in Firefox 35
This should work even in firefox
@media print {
#main{margin:100px 0;}
}
The "@media print" will make sure the style is only used when printing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With