Home > Web Front-end > CSS Tutorial > How to Avoid Unwanted Blank Pages When Using Page Breaks in HTML and CSS?

How to Avoid Unwanted Blank Pages When Using Page Breaks in HTML and CSS?

Patricia Arquette
Release: 2024-10-30 21:23:30
Original
873 people have browsed it

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>
Copy after login

To prevent this issue, consider using the following solution:

<code class="css">@media print {
    html, body {
        height: 99%;    
    }
}</code>
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template