CSS printable page margins

I searched a lot before asking here, but did not find the answer to my question.

I want to insert the top and bottom margins for a page of my site when printing, so I used the usual margin-top and margin-bottom for the print div, but this only affected the first sheet! so I used this as described in W3C CSS2.1. Specification:

 @page { margin-top: 5cm; margin-bottom: 5cm; } 

but does not affect previewing Firefox or printing to PDF. so how can i insert the upper and lower margins (for each print sheet) through CSS? or is there any trick to do this in Firefox?

+6
html css printing
source share
2 answers

AND

  @page { margin-top: 5cm; margin-bottom: 5cm; } 

and

 @media print { body {margin-top: 50mm; margin-bottom: 50mm; margin-left: 0mm; margin-right: 0mm} } 

works fine in firefox 35

+8
source share

This should work even in firefox

  @media print { #main{margin:100px 0;} } 

"@Media Print" ensures that the style is used only when printing. A.

+2
source share

All Articles