5

I am looking to have a 75px margin on the top and bottom of each printed page. I have tried putting the margin on the body and a wrapper div, but both of these options just add a margin to the top and bottom of the whole document. This gives a 75px at the top of the document, then maybe 10px on the top/bottom of the second page, and the last page will have the bottom margin.

I included an image if it will help: https://i.stack.imgur.com/GrTpq.jpg

andygavin
  • 2,784
  • 22
  • 32
Dane
  • 51
  • 1
  • 1
  • 2

3 Answers3

2

The other answers are only partially correct. You should use units with a physical dimension (I prefer using pt instead of cm or mm) and you may want to use a print style sheet. But if you want to style the top and bottom margins of a printed page, you will have to also use the @page rule. You probably need something like this:

<style>
@page {
    margin: 75pt 0;
}
</style>
Chris Broski
  • 2,421
  • 27
  • 23
1

You should use cm or mm as unit (while Printing).

When you specify for printing, pixels will cause the browser to translate it to something similar to what it looks like on screen.

Use cm or mm to ensure consistent size on the paper.

body {
    margin: 0mm 25mm 25mm 0mm;
}
MarmiK
  • 5,639
  • 6
  • 40
  • 49
Tom
  • 19
  • 2
  • This will only add margin to the beginning and end of the document, not each printed page. See me answer on using the @page rule. – Chris Broski Dec 03 '16 at 19:12
0

Add a media type to your CSS

<style>
    div {
        font-family: arial;
        font-size: 10px;
        margin: 10px 10px;
    }
</style>

<style media="print">
    // CSS here will only be applied when printing
    div {
        margin: 5px 5px;
    }
</style>

Your html will have all the css as above but changed the margin values

Kevin Lynch
  • 24,427
  • 3
  • 36
  • 37
  • The document I am trying to print is specifically made just for printing so I do not need the page to look different in the browser than it does on a piece of paper, well besides the margins. – Dane Aug 20 '13 at 21:50