I am having a table in a web page, I need to restrict the number of rows in the table per page (say, each printed page should contain 10 rows) (only in the printed page).
My code is like this:
<style>
@media print {
thead {display: table-header-group;}
}
</style>
<table>
<thead>
<tr>
<th>First Heading</th>
<th>Second Heading</th>
<th>Third Heading</th>
</tr>
</thead>
<tbody>
<tr>
<td>foo</td>
<td>bar</td>
<td>21</td>
</tr>
....
....
</tbody>
</table>
I want to know, is there any possible way to do this using CSS or equivalent way?. Also i'm having an integer values in the 3rd row, i need to print the sum of those rows in each page (say, sum of 10 rows in each page at the end of the page).
Please suggest me some ideas to achieve this. All those to be done only in the printed page not in browser display.
You could use the
nth-child()
selector:This will not work in Chrome, since Chrome requires that a page-break element has to be a block level element.
There is currently no way to sum the content of a column with pure CSS, you would have to use some javascript or server-side processing.
Example:
You would then have to increase
tr:nth-of-type(10n)
totr:nth-of-type(11n)
since this will add a row.