Problem Description:
Despite researching extensively, page numbers fail to appear when printing an HTML document.
CSS Code Used:
@page { margin: 10%; @top-center { font-family: sans-serif; font-weight: bold; font-size: 2em; content: counter(page); } }
The @page rule was attempted both inside and outside the @media all block to no avail.
Solution:
Due to the limitations of web browsers, implementing page numbers using @page is not feasible. An alternative solution is provided by Oliver Kohll, which utilizes table-based formatting in CSS without relying on @page:
CSS:
#content { display: table; } #pageFooter { display: table-footer-group; } #pageFooter:after { counter-increment: page; content: counter(page); }
HTML:
Customization:
The appearance of the page numbers can be customized by modifying the properties of #pageFooter, such as text formatting, positioning, and background styling.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3