Avoid page break inside a div

Discussion in 'CSS' started by alfgeorg, Apr 2, 2008.

  1. #1
    Are there any way to avoid page breaks inside a div?
    I want the page breaks to be before or after the div.
     
    alfgeorg, Apr 2, 2008 IP
  2. jodfran

    jodfran Peon

    Messages:
    79
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Sorry i don't quite understand what you are asking can you please explain again in better english ? :)
     
    jodfran, Apr 3, 2008 IP
  3. nexenator

    nexenator Peon

    Messages:
    41
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    If you meen pagebreaks when printing you can use the following css properties
    page-break-after: (auto|always|avoid|left|right)
    Sets the page-breaking behavior after an element

    page-break-before: (auto|always|avoid|left|right)
    Sets the page-breaking behavior before an element
     
    nexenator, Apr 3, 2008 IP
  4. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #4
    See Paged media. Support is very poor. Only Opera appears to do at all well.

    cheers,

    gary
     
    kk5st, Apr 3, 2008 IP
  5. alfgeorg

    alfgeorg Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Yes, this is for printing, so it is irritating when the page breaks come inside a div (where I dont want it). I also read that page-break-inside:avoid is not supported by most browsers. I hoped there was another solution. Maybe do it programmatically in some way. JavaScript/PHP. ????
     
    alfgeorg, Apr 3, 2008 IP
  6. nexenator

    nexenator Peon

    Messages:
    41
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I used the page-break-inside/before/after in a simple invoicing tool. It did work with the major browsers if I recall this correctly (it's been quite a while though)
     
    nexenator, Apr 4, 2008 IP
  7. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Um, one thing I've stumbled across is even when pagebreak works, FF has this bug (I don't know if it's fixed in Beta 3 yet) where if the div in question is a float, the float totally breaks. And, I'm not sure if it'll print the rest of the float. So if you've got any large floats, remove them from your print.css.
     
    Stomme poes, Apr 4, 2008 IP
  8. nexenator

    nexenator Peon

    Messages:
    41
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    @Stomme poes: I usually put up a print.css where I hide all sidebars and co. So there is no need for floats.
     
    nexenator, Apr 7, 2008 IP
  9. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #9
    Try {page-break-before || after: auto}. That seems to have general support. If you know which div will be at the break, use :always;.

    cheers,

    gary
     
    kk5st, Apr 7, 2008 IP
  10. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Yeah, I actually discovered the float bug while reading up on print css, but if people haven't taken out their floats, or if they didn't say "Screen" for the non-print, then their printing could be inheriting the floats.
     
    Stomme poes, Apr 8, 2008 IP