I'm looking for a CSS only example of how to keep the <thead>
fixed and the <tbody>
scrollable. I've searched and found tons of examples, but none are working.
How do I make this simple table head stay fixed and the table body to scroll. Everytime I try the body 'squishes' under a single th element or doesn't scroll within the 50px height.
HTML:
<table id='recipient-summary'>
<thead class='fixed'>
<tr>
<th>Live</th>
<th>Paid</th>
<th>Dep</th>
<th>Tran</th>
<th>Date & Time</th>
<th>Type</th>
<th>Name</th>
<th>Total</th>
</tr>
</thead>
<tbody class='scrollable'>
<tr>
<td>Bob Dillian</td>
<td>Race for the stars</td>
<td>23 Apr 2015</td>
<td>$144.54</td>
<td>$3.99</td>
<td>Issue Check</td>
<td>Another element</td>
<td>Another element</td>
</tr>
<tr>
<td>Bob Dillian</td>
<td>Race for the stars</td>
<td>23 Apr 2015</td>
<td>$144.54</td>
<td>$3.99</td>
<td>Issue Check</td>
<td>Another element</td>
<td>Another element</td>
</tr>
<tr>
<td>Bob Dillian</td>
<td>Race for the stars</td>
<td>23 Apr 2015</td>
<td>$144.54</td>
<td>$3.99</td>
<td>Issue Check</td>
<td>Another element</td>
<td>Another element</td>
</tr>
<tr>
<td>Bob Dillian</td>
<td>Race for the stars</td>
<td>23 Apr 2015</td>
<td>$144.54</td>
<td>$3.99</td>
<td>Issue Check</td>
<td>Another element</td>
<td>Another element</td>
</tr>
<tr>
<td>Bob Dillian</td>
<td>Race for the stars</td>
<td>23 Apr 2015</td>
<td>$144.54</td>
<td>$3.99</td>
<td>Issue Check</td>
<td>Another element</td>
<td>Another element</td>
</tr>
</tbody>
<tfoot></tfoot>
</table>
CSS:
thead,tbody{ display:block; }
tbody{ height:50px; overflow:auto; }
td{ border:1px solid #777; padding:5px; }