Search code examples
htmlcsscss-tables

How do I make a table scrollable


Does anyone know a vanilla way of making the body of a table scrollable using only html and css?

The obvious solution

tbody {
    height: 200px;
    overflow-y: scroll;
}

does not work.

Wouldnt this be the obvious use of tables?

am I doing something wrong?


Solution

  • You need to declare a height first, else your table will expand to the according width of its content.

    table{
       overflow-y:scroll;
       height:100px;
       display:block;
    }
    

    EDIT: after clarifying your problem I edited the fiddle: check out this Example or that way. It's rather hacky and not guaranteed to work crossbrowser but might work for your case.