简体   繁体   English

打印网页时,我可以使标题保持“附加”到我的内容吗?

[英]Can I keep my headers 'attached' to my content when printing my webpage?

I have a standard webpage, headers, sub headers and blocks of text, repeated down the page. 我有一个标准的网页,标头,子标头和文本块,在页面下重复。 Occasionally this page will be printed directly from the browser. 有时,该页面会直接从浏览器中打印。

Obviously the web page needs to be split up to fit on however many pages are required. 显然,需要拆分网页以适合于任何页面。

The issue I'm having is, some of my sub headers are being left at the bottom of one page and the text is pushed down onto the next page. 我遇到的问题是,我的一些子标题留在了一页的底部,文本被下推到了下一页。

Ideally, I would like the sub headers to 'follow' the text. 理想情况下,我希望子标题“跟随”文本。

Anyone have any suggestions? 有人有什么建议吗? Is this even an issue that can be addressed? 这甚至是可以解决的问题吗?

Using JavaScript or jQuery or some magic CSS3 perhaps? 使用JavaScript或jQuery还是一些神奇的CSS3?

<div id="mainContent">

    <div class="header"></div>
    <div class="subHeader"></div>
    <div class="text">
        //LOTS OF TEXT
    </div>

    <div class="subHeader"></div>
    <div class="text">
        //LOTS OF TEXT
    </div>

    <div class="subHeader"></div>
    <div class="text">
        //LOTS OF TEXT
    </div>

    <div class="header"></div>
    <div class="subHeader"></div>
    <div class="text">
        //LOTS OF TEXT
    </div>

    <div class="header"></div>
    <div class="subHeader"></div>
    <div class="text">
        //LOTS OF TEXT
    </div>

    <div class="subHeader"></div>
    <div class="text">
        //LOTS OF TEXT
    </div>

    <div class="subHeader"></div>
    <div class="text">
        //LOTS OF TEXT
    </div>

    <div class="subHeader"></div>
    <div class="text">
        //LOTS OF TEXT
    </div>

    <div class="header"></div>
    <div class="subHeader"></div>
    <div class="text">
        //LOTS OF TEXT
    </div>

</div>

Cheers! 干杯!

Ideally you need to use a print stylesheet. 理想情况下,您需要使用打印样式表。 This will let you change the CSS specifically for print. 这将使您更改专门用于打印的CSS。

There are various print specific CSS rules but you'd have to try them on a variety of browsers. 有各种特定于打印的CSS规则,但您必须在各种浏览器上尝试使用它们。

For example: page-break-after allows you to insert a page break after the element use use it on 例如:page-break-after允许您在元素使用后在其上插入分页符

http://www.w3schools.com/cssref/pr_print_pageba.asp http://www.w3schools.com/cssref/pr_print_pageba.asp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM