I have a html page with some content on top and table below. How to make the top content and head of table fixed on page and enable only data rows to scroll?
I find only very complicated solutions with javascript, but I wonder does exist some simpler way to do that. The html page is like this:
<div>
top content
</div>
<table>
<thead>
<tr><th> ... first header row
<tr><th> ... second header row
</thead>
<tbody>
... data rows
</tbody>
</table>
3
Answers
You can use CSS.
Give
position: sticky; top: 0;
to your th elements. Or you can give fix height to yourtbody
and addoverflow-y:auto
In the snippet below, the HTML and CSS part are resolving the scrollability of
tbody
, whereas, for the purpose of filling the gap between the upper content and the lower and of the screen, I applied Javascript.