So I have a web page with essentially a table view. The body of the table can scroll horizontally and vertically, but the header should always stay on top and only scroll horizontally (to match the position of the body).
My current solution is to keep the header and body in separate divs, with the header having overflow-x: auto and overflow-y: hidden, and the body having overflow: auto.
Then I have JS code to watching on the "scroll" event so I can programmatically update the horizontal scroll position.
It works, but it's ugly and sometimes there's a little lag, where after scrolling the body the header doesn't immediately update the position.
I've looked at answers to similar questions, but I haven't found a better answer to address horizontal scrolling.
I'm not interested in any framework or 3rd party solutions. Thanks!
How can I let a table's body scroll but keep its head fixed in place?