Table with fluid height and width fixed header, footer and first column using position:sticky
This example uses position:sticky on the th elements in the thead, tfoot and left column to achieve the fixed effect. Browsers that don't support position:sticky will just get a normal table so no harm done. Resize browser smaller to see fixed first column.
BMW x5-Specs:-(Sample Data) | Header H2(Basic SUV) | 2023 BMW X5 H3(SUV XII) | Cell content-H4(SUV XXVI) | Header H5(Sample Data) |
---|---|---|---|---|
First top Column(Sample Data) | Cell content test |
Cell content longer | Cell content with Data here! | Cell content |
Left Column(Sample Data) | Cell content | Cell content longer | Cell content | Cell content |
Left Column(Sample Data) | Cell content | Cell content longer | Cell content | Cell content |
BMW X5 ENgine Specs(text here!) | ||||
Left Column(Sample Data) | Cell content | Cell content longer | Cell content | Cell content |
Left Column(Sample Data) | Cell content | Cell content longer | Cell content | Cell content |
Left Column(Sample Data) | Cell content | Cell content longer | Cell content | Cell content |
Left Column(Sample Data) | Cell content | Cell content longer | Cell content | Cell content |
Left Column(Sample Data) | Cell content | Cell content longer | Cell content | Cell content |
Left Column(Sample Data) | Cell content | Cell content longer | Cell content | Cell content |
BMW X5-Trim Levels(Versions) | Base Version(Entry) | Well-equipped(Mid-level) | Fully-loaded(Top-Level) | Footer 5(Sample Data) |
Works in latest versions of modern browsers i.e. Edge, Chrome, Safari/ios and Firefox. Does not work in IE11 or older browsers but no harm done.
All of the other fixed table headers and footers that I've seen are either fixed width or fixed height or need a continuous update with JS and are very janky. This one is very smooth. You would of course need to linearise the data for smaller screens/mobile but that is a question for another day :). See this example for a demo of how to linearise for mobile.
See JS Version
COMMENTS