Addressing Page Breaks in HTML Table Printing
When printing extensive HTML tables, managing page breaks is crucial to maintain readability. To prevent rows from being split across pages, explore the following solution:
You can employ CSS styles to control page breaks in your HTML table:
table { page-break-inside:auto } tr { page-break-inside:avoid; page-break-after:auto } thead { display:table-header-group } tfoot { display:table-footer-group }
Here's an example HTML table with these CSS styles applied:
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Test</title> <style type="text/css"> table { page-break-inside:auto } tr { page-break-inside:avoid; page-break-after:auto } thead { display:table-header-group } tfoot { display:table-footer-group } </style> </head> <body> <table> <thead> <tr><th>heading</th></tr> </thead> <tfoot> <tr><td>notes</td></tr> </tfoot> <tbody> <tr> <td>x</td> </tr> <tr> <td>x</td> </tr> <!-- 500 more rows --> <tr> <td>x</td> </tr> </tbody> </table> </body> </html>
Implementing these CSS rules ensures that:
The above is the detailed content of How Can I Prevent HTML Table Rows from Splitting Across Pages When Printing?. For more information, please follow other related articles on the PHP Chinese website!