79539901

Date: 2025-03-27 19:55:59
Score: 2
Natty:
Report link

Extending user1124809 's answer (snippet below) so that the tbody and thead fit the width of the table:

Set display: block; for the table Set position: sticky; top: 0; for the header 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.

Reasons:
  • Blacklisted phrase (1): to comment
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): user1124809
  • User mentioned (0): user1124809
  • Low reputation (1):
Posted by: Sean Owen