You need to wrap your whole content inside a table, like:
HTML
<table>
<thead>
<tr><td>
<!-- your header goes here -->
</td></tr>
</thead>
<tbody>
<tr><td>
<!-- your content goes here -->
</td></tr>
</tbody>
<tfoot>
<tr><td>
<!-- your footer goes here -->
</td></tr>
</tfoot>
</table>
... and add the following CSS:
@media print {
thead { display: table-header-group; }
tfoot { display: table-footer-group; }
}
@media screen {
thead { display: block; }
tfoot { display: block; }
}
I need to add, that this may not work in webkit-based browsers (as of now) as Safari, Chrome and Opera. Please test it on all browsers you want to support.
Chrome may support another option: to set header and footer to position:fixed
, but I wasn't able to avoid overlapping with the page content (i.e. very long text over more than one page) in my quick tests.
addendum
You may have content elements you wish to not break upon page-break - e.g. list items spanning multiple lines of text. To avoid this you can set the following CSS:
-webkit-column-break-inside: avoid; /* Chrome, Safari, Opera */
page-break-inside: avoid; /* Firefox */
break-inside: avoid; /* IE 10+ */