Home >Web Front-end >CSS Tutorial >How to Print Web Page Headers and Footers on Every Page?

How to Print Web Page Headers and Footers on Every Page?

Barbara Streisand
Barbara StreisandOriginal
2024-10-25 11:23:02313browse

How to Print Web Page Headers and Footers on Every Page?

Printing Web Page Headers and Footers on Every Page

It is possible to ensure that custom headers and footers appear on every printed page from a web application. While initial research may suggest otherwise, explore the following solution:

Using Tables:

Create a table with a thead (for the header) and tfoot (for the footer) sections. Nesting these sections within the table allows for the dynamic rendering of headers and footers on each printed page.

CSS Styling:

Apply the following CSS styles to control the display of the header and footer:

thead { display: table-header-group; }
tfoot { display: table-footer-group; }

Browser Compatibility:

This approach is ideal for IE6, which has limited CSS support. Note that Firefox is also expected to support it.

For printing-only visibility:

Use @media parameters to specify that the header and footer should only be visible on printed media:

@media print {
  thead { display: table-header-group; }
  tfoot { display: table-footer-group; }
}

@media screen {
  thead { display: none; }
  tfoot { display: none; }
}

Alternative Solution:

If the table approach does not meet your needs, consider generating reports in PDF format using tools like TCPDF. This method provides greater control over page formatting and ensures consistent rendering of headers and footers.

The above is the detailed content of How to Print Web Page Headers and Footers on Every Page?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn