Extending user1124809 's answer (snippet below) so that the tbody
and thead
fit the width of the table
:
Set
display: block;
for thetable
Setposition: sticky; top: 0;
for theheader
row.
To make tbody
and thead
fit the width of the table
:
table {
display: block;
overflow-y: auto;
}
thead {
position: sticky;
}
thead, tbody {
display: table;
width: 100%;
}
Note - Apologies user1124809, I did not have enough rep to comment on the answer with this additional information so I had to reply with my own answer.