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) | 2023 BMW X5 H1(Prev.Mod) | 2024 BMW X5 H2(Curr.Mod) | 2025 BMW X5 H3(Ann.Mod) | |
---|---|---|---|---|
First top Column(Sample Data) | Cell conte-Cell content test | Cell content longer | Cell content longer | |
Transmission Type(Sample Data) | 46.5 lb-ft. at 11,500 rpm (claimed) | Cell content longer | Cell content longer | |
Left Column(Sample Data) | Cell content | Cell content longer | 46.5 lb-ft. at 11,500 rpm (claimed) | |
Rear/Front Suspension high yyv(Sample Data) | 119 hp at 14,250 rpm (claimed) | Cell content longer | Cell content longer | |
Battery Capacity(Sample Data) | Cell content-AWD SUV-1.3ltr 4cyl.1v | Cell content longer | Cell content longer | |
C02 Emissions WMTC(Sample Data) | 17M/CxMT5.50 | Cell content longer-1.3ltr 4v/cyl | Cell content longer | |
Left ColumnXXXY(Sample Data) | Cell content | Cell content longer | Cell content longer | |
Left Column(Sample Data) | Cell content | Cell content longer | Cell content longer | |
Left Column(Sample Data) | Cell content | Cell content longer | Cell content longer-$cyl 1.3 ltr | |
BMW x5 trims(Versions) | Base Version(Entry) | Well-equipped(Mid-level) | Fully-Loaded(Top-level) |
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