Print Issue: Preventing DIV Bifurcation Across Pages
Encountering a printing dilemma where dynamic DIVs are getting sliced in half between pages? This issue arises when trying to print lengthy documents with numerous DIV elements of variable height.
CSS Solution to the Rescue
To address this issue, the CSS property break-inside comes to the rescue. By specifying the value avoid, you can ensure that the rendering engine prevents DIVs from being split mid-way. Here's the code snippet:
@media print { div { break-inside: avoid; } }
This solution is supported by all major browsers, including:
Alternative Option
Another viable option is to use page-break-inside: avoid; instead of break-inside: avoid;. However, this approach has been deprecated and should be used with caution.
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