I'm having trouble getting this working in most browsers, except for IE (it even works correctly in IE6) and Opera.
Firefox separates the divs correctly but only prints the first page.
Chrome and Safari only applies the page break to the last div.
How can I get this working across all browsers correctly?
The HTML:
<div id="leftNav"> <ul> <!--links etc--> </ul> </div> <div id="mainBody"> <div id="container"> <div class="pageBreak"> <!--content--> </div> <div class="pageBreak"> <!--content--> </div> <div class="pageBreak"> <!--content--> </div> </div> </div>
The divs with the IDs #leftNav
and #mainBody
are are set to float:left
, so they display nicely.
I only want to print the .pageBreak
classes, hiding the #leftNav
and the rest of the #mainBody
with CSS.
The CSS:
@media print { #leftNav { display:none; } #mainBody { border:none; margin:none; padding:none; } }
Parent elements can not have float
on them.
Setting float:none
on all parent elements makes page-break-before:always
work correctly.
Other things that can break page-break
are:
page-break
inside tablesinline-block
elementsFor the sake of completion, and for the benefit of others who are having the same problem, I just want to add that I also had to add overflow: visible
to the body tag in order for FireFox to obey the page breaks and even to print more than just the first page.
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