I have a table with a header and a body, and I want the table header to remain fixed while scrolling happens on the body.
The table is set up like so:
<table>
<thead>
<tr>
<th>Header 1</th>
<th>Header 2</th>
<th>Header 3</th>
</tr>
</thead>
<tbody>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
</tr>
...more rows for data...
</tbody>
The table is encapsulated with a and has CSS like:
overflow-x: hidden;
overflow-y: auto;
height: 400px;
I need the table header to remain perfectly still but when I add position: fixed; to thead or to the individual th the header gets squished.
Whats the best approach for this?