It may not be exactly what you're looking for, but one approach is to enclose the table within a wrapper element and apply a overflow: scroll
style to the wrapper.
.wrapper {
height: 200px;
position: relative;
overflow-y: scroll;
}
table td {
border: 1px solid #000;
}
table thead th {
position: sticky;
top: 0;
background: #fff;
padding-bottom: 30px;
}
table tfoot td {
background: #fff;
border: none;
position: sticky;
bottom: 0;
padding-top: 30px;
}
<div class="wrapper">
<table>
<thead>
<tr>
<th>head</th>
<th>head</th>
<th>head</th>
<th>head</th>
<th>head</th>
<th>head</th>
<th>head</th>
<th>head</th>
<th>head</th>
</tr>
</thead>
<tr>
<td>Data</td>
<td>Data</td>
<td>Data</td>
<td>Data</td>
<td>Data</td>
<td>Data</td>
<td>Data</td>
<td>Data</td>
<td>Data</td>
</tr>
<!-- More table rows here -->
<tfoot>
<tr>
<td>foot</td>
<td>foot</td>
<td>foot</td>
<td>foot</td>
<td>foot</td>
<td>foot</td>
<td>foot</td>
<td>foot</td>
<td>foot</td>
</tr>
</tfoot>
</table>
</div>
Edit 1: included thead
& tfoot
sections that are fixed in position.
Edit 2: introduced padding to thead
& tfoot
.
Edit 3: specified vertical scrolling only for the table.