Page break: avoid work

I have a print style sheet for my (Wordpress) site, and I want the images to be printed on one page, and not distributed across pages. In some cases, even lines of text are split into pages. I included img {page-break: avoid;) in my print stylesheet, but no luck. I found a few previous answers, but they seem to be old.

Is there a reliable way to print a medium-sized image on one page and not split it into pages? Why do lines of text break on pages?

picture broken across two pages

lines breaking across pages

Website: http://74.220.217.211/housing-developments/grafton-townhomes/

Related posts:

+9
source share
2 answers

Try the following:

 .site-container, .site-inner (heck body tag possibly) {position:relative;} p { page-break-inside: avoid; position: relative; } 

Tick ​​FIDDLE

Add this to your print media.

I just look at this in Chrome and it looks great, minus the image that also needs this:

 img { page-break-before: auto; page-break-after: auto; page-break-inside: avoid; display: block; } 

Finally, Wordpress has this, but is not really sure if this helps ...

  <!--nextpage--> 
0
source

I think the problem may arise from the position property of the elements. An element that you do not want to tear on the page and its parent should be declared as:

 position: relative; 

The rest of the code styles are correct and should look like

 @media print { img { page-break-before: auto; page-break-after: auto; page-break-inside: avoid; position: relative; } } 
0
source

All Articles