views:

1974

answers:

5

I'm trying to use the page-break-inside CSS directive, the class of which is to be attached to a div tag or a table tag (I think this may only work on block elements, in which case it would have to be the table).

I've tried all the tutorials that supposedly describe exactly how to do this, but nothing works. Is this an issue of browser support or has anyone actually gotten this working, the exact bit of CSS looks like this:

@media print {

.noPageBreak { page-break-inside : avoid; } }

+4  A: 

Safari 1.3+, Opera 9.2+, Konquerer, and IE8 all support it, at least to some degree.

Firefox apparently still does not.

phloopy
I don't think this is true re:safari 1.3+http://reference.sitepoint.com/css/page-break-insideI have also tried it and it didn't work
sequoia mcdowell
A: 

I'm trying to use the page-break-inside CSS directive, the class of which is to be attached to a div tag or a table tag (I think this may only work on block elements, in which case it would have to be the table).

Firstly, there's no need to guess. Just look at the specification, and you'll see that it does indeed only apply to block-level elements.

Secondly, <div> elements are usually block-level elements, so there's no problem applying page-break-inside to a <div> element.

Finally, you don't need to wrap it in @media. You only need @media if you want to apply media-independent rules to only one medium, for instance, if you want to use display: block only for one medium. In this case, you don't need to hide those rules from other media, because they'll only apply to paged media anyway.

Jim
A: 

Safari 1.3 and later support page-break-inside.

So does Konqueror.

Jim
+3  A: 

Safari 1.3 and later (don't know about 4) do not support page-break-inside (try it, or see here: http://reference.sitepoint.com/css/page-break-inside). Neither do Firefox 3 or IE7 (don't know about 8).

In a practical sense, support for this attribute is SO spotty, it doesn't make sense to use it at all at this point. You'd be lucky if even 10% of your visitors have browsers that can support this.

The solution I used was to add

page-break-after:always

to certain divs, or add a "page-breaker" div in where you want breaks. This is quite ham-handed, I know, because it doesn't do quite what you want, and causes content to not reach the bottom of the printed page, but unfortunately there isn't a better solution (prove me wrong!).

Another approach is to create a stylesheet that removes all extraneous elements (display:none) and causes the main content to flow in one main column. Basically, turn it into a single column, text-only document.

Finally, avoid floats and columns when styling for printers, it can make IE (and FF) act wacky.

sequoia mcdowell
A: 

From preliminary searches, it's hard to find up-to-date statistics on browser support for this, but it seems that Firefox 4beta6 supports it and Chrome 7 does not. Chrome also breaks pages halfway through a line of text, so that part of the text appears on one page and part appears on the next. Uncharacteristic lack of attention to detail, but I guess neither Google nor Apple care about printing things.

Firefox 4 also adds some nice headers and footers to your prints with url, page title, site title, number of pages, and time. Nice.

chadoh