SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Aug 2006
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    page-break-before

    Hello,

    I am trying to create a print style for my website and I am trying to figure out how to best control page breaks.

    One thing that I noticed is that sometimes the copyright notice at the bottom is pushed alone in the second page. I would prefer to either fir it in the first page or to push somehting more on the second page.

    I thought that by using "page-break-before: avoid" on the copyright notice that I would achieve just that. But it doesn't seem to do anything!

  2. #2
    SitePoint Addict
    Join Date
    Aug 2006
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Similarly, the "page-break-inside: avoid" doesn't seem to work either. I have a div with a blue border around it and half of it appears on one page and the other half on another. This happens with Both FF2 and IE7

  3. #3
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Only Opera supports page-break-inside and it's also the only one with full support for page-break-before.

    IE should support page-break-before:avoid, but Firefox and Safari only support the values always and auto.
    Birnam wood is come to Dunsinane

  4. #4
    SitePoint Addict
    Join Date
    Aug 2006
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. This is what mislead me: http://phpeye.com/clientrefs/CSS.fie...ak-before.html

    So is there any practical way to avoid having elements break in the middle between 2 pages?

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    The only way that currently works cross browser is to add style="page-break-before:always" to the actual tag in the HTML. If you move it into a style tag at the top of your page or an external stylesheet then it should still work in most browsers but there are some browser versions that only support it inline. As you have found out, few browsers support any form of conditional test so that it wont break before if it will actually all fit on the current page. Unfortunately while there are only two common paper sizes that people are likely to be using to print the page, different printers set different margins and so the amount of content that will actually fit on a page can vary. Perhaps the simplest solution would be to set the margins for your page big enough that printers will not need to make the content any narrower (eg by setting the width to 750 points which allows for A4 paper being slightly narrower than letter as well as allowing for printer margins) and then work out where the content will actually fall on letter sized pager (which is shorter than A4) so as to force breaks where required. That way as long as your visitor isn't overriding your styles you can be sure that your content will not break in the middle of something you don't want broken. It may take several goes at previewing the print page on both A4 and letter sized paper to make sure you have put your break-befores in the right places.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •