开发者

page-break-after with IE and FF not working as expected

开发者 https://www.devze.com 2023-01-05 07:09 出处:网络
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:

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 conten开发者_StackOverflow中文版t content content content content content content content content content 
            content content content content content content content content content content content content 
            content content content content content content content content content content content content 
            content content content content content content content content content content content content 
            content content content content content content content content content content content content 
            content content content content content content content content content content content content 
            content content content content content content content content content content content content 
            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?


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消