Using CSS to keep paragraphs/blocks together when printing

Is there a way to keep a block of text together, either in a DIV tag or as P tag, when you print a page? Example. A quotation page with many items, and at the end there is a disclaimer and signature area that must be together, either on the first page or next page.

Is this possible at all??  I have searched but cannot see anything for this.
Who is Participating?
David S.Connect With a Mentor Commented:
It seems I should have explained more.

The property you want is page-break-inside, however, only recent versions of Opera support it, so it won't do you much good. Likewise, only recent versions of Opera are the only browsers to support the orphans and widows properties.

Thus you're stuck with page-break-before and page-break-after. The default value for each of those properties is "auto", so declaring it doesn't do any good. Because browsers only partially support those properties you're down to two choices: page-break-before:always and page-break-after:always
David S.Commented:
Try using the page-break-before property:
mandymooAuthor Commented:
Unfortunately this doesn't fix the problem.
Applying this to the #invfooter DIV style, still allows its contents to be split over 2 pages, as I'm wanting either all the info on the same page (if short quote) or the info to be on the next page in full.

Code sample:
#invfooter {
      clear: both;
      width: 650px;
      margin-top: 0px;
      margin-right: auto;
      margin-left: auto;
      font-size: 11px;
      line-height: 14px;
      text-align: right;
      page-break-before: auto;

I have also tried "orphans"... do I have to use them both together?? Again I have tried this above with "orphans: 12".

Any other suggestions?
quincydudeConnect With a Mentor Commented:
try page-break-after

see the examples in on how to use it, and set it to always
mandymooAuthor Commented:
Right, Ok. Thanks Kravimir.

I was a little discouraged, but I have resolved the issue with a little help from PHP!

They way I got around it was to have a form on my print page, where I can indicate if I want to break the page or not. After indicating I want to break the page, it passes a value to the URL string of "break=always" to the same page. Then, in my stylesheet, I added the variable to it. The CSS is called in when the page loads and everything works beautifully.

Code sample:
#invfooter {
      page-break-before: $_GET['break'];

So a combination of CSS & PHP allows me to break the page at a certain place if the page is too long for 1 page.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.