Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

page-break-inside doesn't work in Chrome?

I have a bunch of paragraphs on a page:

<p> ... </p> <p> ... </p> <p> ... </p> 

The CSS rule for those paragraphs is:

p {     margin: 20px 0;     page-break-inside: avoid; } 

Live demo: http://jsfiddle.net/KE9je/2/show/

If I understand the page-break-inside property correctly, the above should ensure that no paragraph is split between two pages. (A paragraph is either displayed on the "current" page, or if it doesn't fit completely, it's moved to the next page.)

This doesn't seem to work in Chrome. Open the demo, right-click the page, choose "Print...". You'll see a print preview - the fifth paragraph is split between page 1 and 2.

What am I doing wrong? How can I make this work in Chrome?


like image 788
Šime Vidas Avatar asked Oct 09 '11 20:10

Šime Vidas


People also ask

How does page-break inside work?

The page-break-inside property in CSS is used to specify how the page breaks inside the element to which it is applied while printing. It inserts a page break or sometimes it used to avoid page break inside an element while printing. Property Values: auto: It is the default value.

How do you handle page breaks when printing a large DIV in HTML?

To fix this just change it to page-break-after:auto. It will break correctly and not create an extra blank page.

How do I insert a page-break in a Web page?

To suggest a page break, add <P style="page-break-before: always"> before the beginning of a new printed page. For example, if you place the following tags on a HTML page and print it using a compatible browser, you will end-up with three pages with the sample text.


1 Answers

Actually, it DOES work in Chrome, and the solution is really silly!!

Both the parent and the element onto which you want to control page-breaking must be declared as:

position: relative; 

Check out this fiddle (or in fullscreen)

This is true for:

page-break-before page-break-after page-break-inside 

However, controlling page-break-inside in Safari does not work (in 5.1.7, at least)

I hope this helps!!!

like image 75
Peter Avatar answered Sep 20 '22 18:09

Peter