简体   繁体   English

添加两个页眉和页脚,一个用于屏幕和打印

[英]Adding two headers and footers, one for screen and print

As far as I understand in HTML5, you should only have one header tag and one footer tag in a document (or at least in a section). 据我对HTML5的了解,您在文档中(或至少在一部分中)应该只包含一个标头标签和一个页脚标签。 But what if you want one footer to appear on screen and a different one to appear when printing. 但是,如果要在屏幕上显示一个页脚,而在打印时显示另一个页脚,该怎么办。 As far as the HTML is concerned, you are adding two footers together, even though only one would appear at a time. 就HTML而言,即使一次只出现一个页脚,您也要添加两个页脚。

Would screen readers, for example, ignore the print version? 例如,屏幕阅读器会忽略打印版本吗?

One way of doing this is to put two sections in each, one to be displayed on screen (.noprint) and the other to be displayed for print (.print). 一种方法是将每个部分放在两个部分中,一个部分显示在屏幕上(.noprint),另一部分显示用于打印(.print)。 Display .noprint as you would and set .print to display none except for when being printed using an '@media print' query. 按原样显示.noprint,并将.print设置为不显示,除非使用'@media print'查询进行打印。

like this: 像这样:

<header>

    <div class="noprint">
        <p>stuff for screen only goes here</p>
    </div>

    <div class="print">
        <p>stuff for print only goes here</p>
    </div>

</header>

<style>
.print {
    display: none;
}

@media print {
    .print {
        display: inherit;
    }
    .noprint {
        display: none;
    }
}
</style>

Also, to answer your question about screen readers: they usually will not read an element set to display:none and I believe that to be true in this case. 另外,为回答有关屏幕阅读器的问题:他们通常不会阅读设置为display:none的元素,我相信在这种情况下是正确的。 Here's a more comprehensive guide on how screen readers deal with display:none: 这是有关屏幕阅读器如何处理显示的更全面的指南:无:

http://juicystudio.com/article/screen-readers-display-none.php http://juicystudio.com/article/screen-readers-display-none.php

good luck! 祝好运!

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

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