views:

33

answers:

1

I have read through a lot of the question asked here and other places and I am confused why page-breaks don't seem to work for me. I created a test html page that looks like this:

<html>
    <head>
        <style type="text/css">
            @media all
            {
                .page-break { }
            }

            @media print
            {
                div {page-break-after:always; }
            }
        </style>
    </head>
    <body>
        <div class="page-break">
            1content content content content content content content content content content content content 
            content content content content content content content content content content content content 
            content content content content content content content content content content content content 
            content content content content content content content content content content content content 
            content content content content content content content content content content content content 
            content content content content content content content content content content content content 
            content content content content content content content content content content content content 
            content content content content content content content content content content content content 
            content content content content content content content content content content content content 
            content content content content content content content content content content content content 
            content content content content content content content content content content content content 
            content content content content content content content content content content content content 
            content content content content content content content content content content content content 
            content content content content content content content content content content content content 
            content content content content content content content content content content content content 
            content content content content content content content content content content content content 
        </div>
        <div class="page-break">
            2content content content content content content content content content content content content 
            content content content content content content content content content content content content 
            content content content content content content content content content content content content 
            content content content content content content content content content content content content 
            content content content content content content content content content content content content 
            content content content content content content content content content content content content 
            content content content content content content content content content content content content 
            content content content content content content content content content content content content 
            content content content content content content content content content content content content 
            content content content content content content content content content content content content 
            content content content content content content content content content content content content 
            content content content content content content content content content content content content 
            content content content content content content content content content content content content 
            content content content content content content content content content content content content 
            content content content content content content content content content content content content 
            content content content content content content content content content content content content 
        </div>
...
</body>
</html>

I have nine of these divs. Simple enough right? This works just fine (it puts each div on a separate page as expected). Now for the stuff that is not working for IE and FF. My goal here is to create a simple html document that never breaks inside one of these 9 divs. If I change my div style to be page-break-inside:avoid it has absolutely no effect in IE or FF. If I try page-break-after:avoid or page-break-after:auto it doesn't seem to have any effect on the simple html document. Am I missing something. Does anyone have a solution that will work in both Explorer and FireFox?

A: 

Unfortunately, Firefox doesn't support "page-break-inside" so your best bet is to use "page-break-before: always". That is supported by IE and Firefox and will ensure each DIV has a full page of space to use. I would also not apply the class to the first DIV, as that would force an unnecessary break. Here is the markup:

<html>
    <head>
        <style type="text/css">
            @media print
            {
                .page-break { page-break-before: always; }
            }
        </style>
    </head>
    <body>
        <div>
            1content content content content content content content content content content content content 
            content content content content content content content content content content content content
        </div>
        <div class="page-break">
            2content content content content content content content content content content content content 
            content content content content content content content content content content content content
        </div>
...
</body>
</html>
David Lantner
Thank you for your response. This approach would work fine if I only wanted one div per page, but I want to fit as many on the page as I can without splitting a div in half. Does this make sense? In my html report I have various sections that vary in height. I want to fit as many on the page as I can without having a page-break in the middle of the section.
testing123
Now I see what you mean. To expand on what I said earlier, Firefox doesn't currently support *any* of the page-break-* features, as tracked by bug 132035:https://bugzilla.mozilla.org/show_bug.cgi?id=132035
David Lantner
Does IE? I couldn't get it to work in IE8 either. Truth be told if I could get it to work in IE I would be satisfied (almost all of our users use >= IE7).
testing123