Home > Article > Web Front-end > How to Avoid Unwanted Blank Pages When Using Page Breaks in HTML and CSS?
Avoiding Unwanted Blank Pages During Printing
In HTML and CSS, page breaks can be controlled using the page-break-after and page-break-before properties. However, sometimes using these properties can result in extra blank pages before or after the intended break.
For instance, the following code prints an extra blank page after the content due to page-break-after: always;:
<code class="html"><div class="print" style="page-break-after: always;">fd</div> <div class="print" style="page-break-after: always;">fdfd</div></code>
To prevent this issue, consider using the following solution:
<code class="css">@media print { html, body { height: 99%; } }</code>
This CSS rule effectively reduces the height of the HTML and body elements to 99%, preventing the browser from adding an extra blank page after the content.
The above is the detailed content of How to Avoid Unwanted Blank Pages When Using Page Breaks in HTML and CSS?. For more information, please follow other related articles on the PHP Chinese website!