5

When there is a html with a table and you want to print it, the table may or may not split depending on how long the table is. If it splits there is a way to repeat the header of the table, to do that you can add:

thead {
  display: header-table-group;
}

What I want to do is to skip the first page, so the header will only show on subsequent pages.

Is there a way to do this?

4

1 回答 1

1

如果您<thead>的高度固定,那么很容易将其隐藏在第一页上。您所要做的就是将表格嵌套在divwithoverflow: hidden;中,然后在表格中添加一个负的上边距以隐藏其标题。

例子:

<style>
  .headless {
    overflow: hidden;
    line-height: 20px;
  }
  .headless > table {
    margin-top: -22px;
    border-spacing: 0;
  }
  .headless > table > * > tr > * {
    border-right: 2px solid black;
    border-bottom: 2px solid black;
    padding: 0 4px 0 4px;
  }
  .headless > table > * > tr > :first-child {border-left: 2px solid black;}
  .headless > table > thead > :first-child > th {border-top: 2px solid black;}
</style>

<div class="headless">
  <table>
    <thead>
      <tr>
        <th>Header</th>
        <th>Header</th>
        <th>Header</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>data</td>
        <td>data</td>
        <td>data</td>
      </tr>
      <tr>
        <td>data</td>
        <td>data</td>
        <td>data</td>
      </tr>
    </tbody>
  </table>
</div>

请注意,标题只会显示在支持重复表标题的浏览器中的后续页面上,不包括 Chrome、Safari 或 Opera。

于 2014-09-10T22:21:45.270 回答