Cross-Browser Support of 'Page-Break-Inside: Avoid;'

Cross-browser support of `page-break-inside: avoid;`

Webdevout.net is a great place to check browser CSS compatibility.

For page-break-inside only IE8 and Opera 8+ are shown to support it

avoid page break inside row of table

You might try this with CSS:

<table class="print-friendly">
<!-- The rest of your table here -->
</table>

<style>
table.print-friendly tr td, table.print-friendly tr th {
page-break-inside: avoid;
}
</style>

Most CSS rules don't apply to <tr> tags directly, because of exactly what you pointed out above - they have a unique display style, which doesn't allow for these CSS rules. However, the <td> and <th> tags within them usually do allow this kind of specification - and you can easily apply such rules to ALL child-<tr>'s and <td>'s using CSS as shown above.

Can I force a page break in HTML printing?

Add a CSS class called "pagebreak" (or "pb"), like so:

@media print {
.pagebreak { page-break-before: always; } /* page-break-after works, as well */
}

Then add an empty DIV tag (or any block element that generates a box) where you want the page break.

<div class="pagebreak"> </div>

It won't show up on the page, but will break up the page when printing.

P.S. Perhaps this only applies when using -after (and also what else you might be doing with other <div>s on the page), but I found that I had to augment the CSS class as follows:

@media print {
.pagebreak {
clear: both;
page-break-after: always;
}
}

Safari page-break-inside:avoid not working

Try using display: inline-block; instead of page-break-inside: avoid;. You may also want to add vertical-align: top; and width: 100%; to make the elements behave like normal block elements instead of inline elements.

This technique has been working reliably since long before page-break-inside: avoid; was implemented in most browsers. It's still the most reliable cross-platform way to prevent page breaks in a block of content.

If you want to make a table unbreakable, you can set display: inline-table; on it. Or you can just put it in an inline-block div.

CSS Page-Break Not Working in all Browsers

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:

  • using page-break inside tables
  • floating elements
  • inline-block elements
  • block elements with borders


Related Topics



Leave a reply



Submit