打印大型HTML表時(shí)如何處理分頁(yè)符我有一個(gè)項(xiàng)目,它需要打印一個(gè)包含許多行的HTML表。我的問(wèn)題是表格在多頁(yè)上的打印方式。它有時(shí)會(huì)將一行切成兩半,這使得它無(wú)法讀,因?yàn)槠渲幸话朐陧?yè)面的邊緣,其余的則打印在下一頁(yè)的頂部。我能想到的唯一可行的解決方案是使用堆疊的div,而不是表和強(qiáng)制分頁(yè)(如果需要的話(huà))。但在我經(jīng)歷所有的改變之前,我想我可以在這里問(wèn)一問(wèn)。
3 回答

Qyouu
TA貢獻(xiàn)1786條經(jīng)驗(yàn) 獲得超11個(gè)贊
<!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>

月關(guān)寶盒
TA貢獻(xiàn)1772條經(jīng)驗(yàn) 獲得超5個(gè)贊
<html><head><style>@media print{ table { page-break-after:auto } tr { page-break-inside:avoid; page-break-after:auto } td { page-break-inside:avoid; page-break-after:auto } thead { display:table-header-group } tfoot { display:table-footer-group }}</style></head><body>....</body></html>

慕妹3146593
TA貢獻(xiàn)1820條經(jīng)驗(yàn) 獲得超9個(gè)贊
<!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 } div { page-break-inside:avoid; } /* This is the key */ 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> <tr> <td><div>Long<br />cell<br />should'nt<br />be<br />cut</div></td> </tr> <tr> <td><div>Long<br />cell<br />should'nt<br />be<br />cut</div></td> </tr> <!-- 500 more rows --> <tr> <td>x</td> </tr> </tbody> </table></body></html>
page-break-inside:avoid
display:block
TR
page-break-inside:avoid
添加回答
舉報(bào)
0/150
提交
取消