This is one of many problems I’ve been having with Firefox since I started working on the printouts for my current project.
What’s happening is that, when the dynamic content above a table grows to the point that there is only enough room left on the page for the table’s header row, instead of bumping the whole table to the next page like it should, Firefox prints an orphaned header row at the bottom of the page.
The following example assumes 8.5"x11" paper with top and bottom margins of 0.5". (Note that the actual number you have to enter in FF’s Page Setup dialog in order to actually get 0.5" margins may not be 0.5. For me, 0.329 did the trick):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
body {
margin: 0;
padding: 0;
font-family: Arial, Helvetica, sans-serif;
line-height: 18px;
font-size: 14px;
}
table {
width: 700px;
margin: 0 auto 0 auto;
table-layout: fixed;
border-spacing: 0;
}
th, td {
padding: 0;
border: solid black;
border-width: 0 1px 1px 0;
}
th:first-child, td:first-child {
border-left-width: 1px;
}
th {
border-top-width: 1px;
}
</style>
</head>
<body>
<div style="height: 920px;">
<!--resize this div to change page break location-->
</div>
<table>
<thead>
<tr>
<th>
Header
</th>
<th>
Header
</th>
</tr>
</thead>
<tfoot>
<tr>
<td>
Footer
</td>
<td>
Footer
</td>
</tr>
</tfoot>
<tbody>
<tr>
<td>
Data
</td>
<td>
Data
</td>
</tr>
<tr>
<td>
Data
</td>
<td>
Data
</td>
</tr>
<tr>
<td>
Data
</td>
<td>
Data
</td>
</tr>
</tbody>
</table>
</body>
</html>
The only way I’ve found to deal with this problem is to create an inline-block element that is the same height as the header row and the first data row, and layer it behind the table using negative margins, like so:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
body {
margin: 0;
padding: 0;
font-family: Arial, Helvetica, sans-serif;
line-height: 18px;
font-size: 14px;
}
table {
width: 700px;
margin: 0 auto 0 auto;
table-layout: fixed;
border-spacing: 0;
}
th, td {
padding: 0;
border: solid black;
border-width: 0 1px 1px 0;
}
th:first-child, td:first-child {
border-left-width: 1px;
}
th {
border-top-width: 1px;
}
</style>
</head>
<body>
<div style="height: 920px;">
<!--resize this div to change page break location-->
</div>
<div style="display: inline-block; height: 39px;">
</div>
<div style="margin-bottom: -39px;">
</div>
<table>
<thead>
<tr>
<th>
Header
</th>
<th>
Header
</th>
</tr>
</thead>
<tfoot>
<tr>
<td>
Footer
</td>
<td>
Footer
</td>
</tr>
</tfoot>
<tbody>
<tr>
<td>
Data
</td>
<td>
Data
</td>
</tr>
<tr>
<td>
Data
</td>
<td>
Data
</td>
</tr>
<tr>
<td>
Data
</td>
<td>
Data
</td>
</tr>
</tbody>
</table>
</body>
</html>
This solution works ok, but I was wondering if anyone had come up with one that doesn’t require extra markup, and/or adapts automatically to changes in the header and data row heights. I would prefer to avoid javascript, if possible.