How to Prevent DIVs from Being Cut Off During CSS Printing?

Susan Sarandon
Release: 2024-11-01 21:29:29
Original
412 people have browsed it

How to Prevent DIVs from Being Cut Off During CSS Printing?

Prevent Cut-Off DIVs During CSS Printing

When generating dynamic HTML content with varying heights, it's common to encounter the problem of DIVs getting cut off between pages during printing. This issue can make printouts difficult to use.

To resolve this, try the following CSS:

<code class="css">@media print {
  div {
    break-inside: avoid;
  }
}</code>
Copy after login

The break-inside: avoid property prevents page breaks from occurring within DIV elements, ensuring that they print on a single page. This property is supported by all major browsers, including Chrome, Edge, Firefox, Opera, and Safari.

As an alternative, you can use page-break-inside: avoid;, which has been deprecated by break-inside: avoid but should still work.

The above is the detailed content of How to Prevent DIVs from Being Cut Off During CSS Printing?. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!