Applying “page-break-before” to a table row (tr)

你说的曾经没有我的故事 提交于 2019-11-27 23:41:04

Inside <head>, set this style

<head>
    <style>
        @media print {
            tr.page-break  { display: block; page-break-before: always; }
        }   
    </style>
</head>

That way, it will produce a page break during printing right before this table row.

<tr class="page-break">
</tr>
JSuar

The site you referenced states that <tr> "may also be considered a block-level element since it may contain block-level elements." Neither the W3.org or Mozilla docs state that <tr> is a block-level element.

Some Possible Solutions

  1. Based on the wording and your example, I would ensure that the cell contains a true block-level element. Here are two examples using <h1> and <p> which are block-level text elements.

    <tr style="page-break-after: always"><td><h1>Next Section</h1></td></tr>
    <tr style="page-break-after: always"><td><p>This will be a new page.</p></td></tr>
    
  2. Others have reported similar problems and one of the solutions might work for you.

  3. As mentioned by My Lister, you could attempt to catch the printing action or generate a print version of the page that would separate the table out so you can obtain the desired page break after every five rows.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!