css-tables-demo
css-tables-demo copied to clipboard
Thank you! 🙂
Just wanted to say thank you so much for this code snippet! 🙂
After spending two days trying to figure out how to have a table that scrolls horizontally with a table body that scrolls vertically, I finally found your article on this! 🙂 (https://joshondesign.com/2015/05/23/csstable)
For me, the magic piece was putting width: fit-content
on the <tbody>
.
By the way, for anyone else who runs across this repo, there are two changes to the code that you probably want to make:
- For overflow, use
auto
instead ofscroll
, so that the scrollbars are only shown when needed. - Use
width: fit-content
instead ofwidth: -webkit-fit-content
Thank you again!! 🙂
I'm glad this helped you. This method is 7 years old, however, so there's probably better ways to do it now using position:sticky
.