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) | 2024 BMW X5 H3(Basic SUV) | Options(SUV more!) | ||||
---|---|---|---|---|---|---|
First top Column(Sample Data) | Cell conte-Cell content test | #1 | ||||
Transmission Type(Sample Data) | 46.5 lb-ft. at 11,500 rpm (claimed) | #2 | ||||
Left Column(Sample Data) | Cell content | #4 | ||||
BMW X5 ENgine Specs(text here!) | ||||||
Rear/Front Suspension high yyv(Sample Data) | 119 hp at 14,250 rpm (claimed) | #5. | ||||
Battery Capacity(Sample Data) | Cell content | #6. | ||||
C02 Emissions WMTC(Sample Data) | 17M/CxMT5.50 | GST 18% here | ||||
Left ColumnXXXY(Sample Data) | Cell content | #7 | ||||
Left Column(Sample Data) | Cell content | #8.. | ||||
Left Column(Sample Data) | Cell content | Cell #9.. | ||||
BMW x5 trims(Versions) | Base Version(Entry) | Top#, |
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