How to use HTML to print header and footer on every printed page of a document?

前端 未结 20 1335
迷失自我
迷失自我 2020-11-21 16:51

Is it possible to print HTML pages with custom headers and footers on each printed page?

I\'d like to add the word \"UNCLASSIFIED\" in Red, Arial, size 16pt to the t

20条回答
  •  隐瞒了意图╮
    2020-11-21 17:10

    Use page breaks to define the styles in CSS:

    @media all
      {
      #page-one, .footer, .page-break { display:none; }
      }
    
    @media print
      {
      #page-one, .footer, .page-break   
        { 
        display: block;
        color:red; 
        font-family:Arial; 
        font-size: 16px; 
        text-transform: uppercase; 
        }
      .page-break
        {
        page-break-before:always;
        } 
    }
    

    Then add the markup in the document at the appropriate places:

    unclassified

    unclassified

    unclassified

    unclassified

    unclassified

    References

    • CSS Paged Media: Page Breaks

    • MDN: page-break-before

    • MDN: break-before

    • Multi-column Layout

    • XHTML Print: Second Edition

    • Webkit Bug 5097: CSS2 page-break-after does not work

    • Print HTML FAQ: Will the program respect CSS styles such as page-break-after?

    • How to deal with page breaks when printing a large HTML table

提交回复
热议问题