Reputation: 135
I have a really long table that when printed, spans several pages.
Currently, when printing the table, the header row only appears at the very top of the table and not at the top of each page.
How can I make the browser (specifically chrome) print a "sticky" table header at the top of every printed page?
My html:
<table>
<!--header-->
<tr>
<td>Col 1</td>
<td>Col 2</td>
<td>Col 3</td>
<td>Col 4</td>
</tr>
<!--body-->
<tr>
<td>Row 1</td>
<td>Row 1</td>
<td>Row 1</td>
<td>Row 1</td>
</tr>
<tr>
<td>Row 2</td>
<td>Row 2</td>
<td>Row 2</td>
<td>Row 2</td>
</tr>
. . . . . .
<tr>
<td>Row nth</td>
<td>Row nth</td>
<td>Row nth</td>
<td>Row nth</td>
</tr>
</table>
Upvotes: 1
Views: 449
Reputation: 19571
To make this work properly, just make sure you are using the <thead>
and <tbody>
tags in your html like the below. With those elements in place, every major browser I know of will know how to handle the page breaks automatically:
<table>
<thead>
<tr>
<th>Col 1</th>
<th>Col 2</th>
<th>Col 3</th>
<th>Col 4</th>
</tr>
</thead>
<tbody>
<tr>
<td>Row 1</td>
<td>Row 1</td>
<td>Row 1</td>
<td>Row 1</td>
</tr>
....
</tbody>
</table>
Upvotes: 1