Home > Web Front-end > CSS Tutorial > How Can I Reliably Force Page Breaks When Printing from Google Chrome?

How Can I Reliably Force Page Breaks When Printing from Google Chrome?

DDD
Release: 2024-12-10 21:17:17
Original
147 people have browsed it

How Can I Reliably Force Page Breaks When Printing from Google Chrome?

Page Breaks in Google Chrome Printing

In Google Chrome, achieving page breaks during printing can be challenging. Despite documentation suggesting the validity of page-break-after: always;, this method may not always work effectively.

Solution

To reliably force page breaks in Chrome, the following approach has been proven successful:

Create a unique

for each page you want to break.

Assign the CSS class "page" to each

.

Within the "print" media query of your CSS, define the following rules:

div.page {
  page-break-after: always;
  page-break-inside: avoid;
}
Copy after login

For example:

<div class="page">
  <h1>This is Page 1</h1>
</div>
<div class="page">
  <h1>This is Page 2</h1>
</div>
<div class="page">
  <h1>This is Page 3</h1>
</div>
Copy after login

By following this approach, you can ensure consistent page breaks when printing from Google Chrome, regardless of the content size or complexity.

The above is the detailed content of How Can I Reliably Force Page Breaks When Printing from Google Chrome?. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template