Solution 1 :

You may use instead a wrapper and position:sticky, this way the table-layout algorythm works for the whole table and every columns and rows remain perfectly aligned.

Classic usage in the snippet below :

.myTableWrapper {
width:min-content;/* wraps onto table's width */
height: 100px;
overflow-y:auto;
padding-right:1.3em;
}
thead {
background:white;
position:sticky;
top:0;
}
<div class="myTableWrapper">
  <table>
    <thead>
      <tr><th>TH</th><th>TH</th><th>TH</th><th>TH</th><th>TH</th></tr></thead>
    <tbody>
      <tr><td>td</td><td>td</td><td>td</td><td>td</td><td>td</td></tr>
      <tr><td>td</td><td>td</td><td>td</td><td>td</td><td>td</td></tr>
      <tr><td>td</td><td>td</td><td>td</td><td>td</td><td>td</td></tr>
      <tr><td>td</td><td>td</td><td>td</td><td>td</td><td>td</td></tr>
      <tr><td>td</td><td>td</td><td>td</td><td>td</td><td>td</td></tr>
      <tr><td>td</td><td>td</td><td>td</td><td>td</td><td>td</td></tr>
      <tr><td>td</td><td>td</td><td>td</td><td>td</td><td>td</td></tr>
      <tr><td>td</td><td>td</td><td>td</td><td>td</td><td>td</td></tr>
      <tr><td>td</td><td>td</td><td>td</td><td>td</td><td>td</td></tr>
      <tr><td>td</td><td>td</td><td>td</td><td>td</td><td>td</td></tr>
      <tr><td>td</td><td>td</td><td>td</td><td>td</td><td>td</td></tr>
      <tr><td>td</td><td>td</td><td>td</td><td>td</td><td>td</td></tr>
      <tr><td>td</td><td>td</td><td>td</td><td>td</td><td>td</td></tr>
      <tr><td>td</td><td>td</td><td>td</td><td>td</td><td>td</td></tr>
    </tbody>
  </table>
</div>

or you can play with display:grid and display:contents to avoid a wrapper and switvh from a table-layou to a grd model .

resizeable live example with sticky headers => https://codepen.io/gc-nomade/pen/abboqbR , but display:contents is not understood yet everywhere .

Problem :

I have a problem with displaying my scrollable table. I want to scroll only table’s body without header. When I set “display: block” parameter it misaligns table and it does not look such good as withot this parameter. But when I delete “display: block” then the possibility of scrolling disappear. Do you know any other ways to make tables scrollable? Thank you in advance for help!

Comments

Comment posted by Rainbow

When using a table you must not touche the display property of any of the table’s elements, now what you want to achieve can’t be done with plain table, you’d need to wrap the table with a scroll able element

By