This has been asked a zillion times: here, there, and the other place just on SO. Yet there’s no real good answer that I can find.
<recap> Often I have tables that are vertically much deeper than the viewport. I’d like to be able to scroll the table’s <tbody> while its <thead> remains fixed and visible. Some of these tables are also much wider than the viewport. Here I want the table’s <thead> to scroll horizontally.
To get the effect, I have dozens of lines of JS, including setInterval( ) calls to check scrollLeft and scrollTop, so that I can reposition a copy of <thead>1. It works but it’s a huge, ungainly, frail and unmaintainable pain in the ass.</recap>
Question: Is there some straightforward css3 way, existent or emerging or proposed, that I can use to get a a table’s <thead> and <tbody> to scroll horizontally and vertically, yet independently of each other?
Thanks!
1 Why setInterval( )? Because IE doesn’t uniformly deliver onScroll events, you silly; everybody knows that!
a dirty way would be to put the header table in a separate div like:
Then body in the another div like:
Now you can give a fixed height to body
divand setoveflowtoauto. like:here is a working example I did in jsfiddle