


Can CSS Alone Create a Cross-Browser Compatible Scrollable Table with Fixed Headers?
CSS-Only Scrollable Table with Fixed Headers
Question:
Is there a CSS-only solution to create scrollable tables with fixed headers that is cross-browser compliant?
Requirements:
- Maintain column alignment between header, footer, and content rows
- Keep the header and footer fixed while the content scrolls vertically
- No jQuery or JavaScript required
- Use only table-related tags (table, thead, tbody, tr, th, td)
Solution using Position: Sticky:
Compatibility Note: Check support for position:sticky before using this solution.
position:sticky positions an element relative to the nearest scrolling ancestor or the viewport if there are no scrolling ancestors. This behavior aligns with the desired sticky header.
However, assigning position:sticky to
cells within a wrapper element that defines the scroll overflow.
Code: div { display: inline-block; height: 150px; overflow: auto; } table th { position: -webkit-sticky; position: sticky; top: 0; } /* Styling */ table { border-collapse: collapse; } th { background-color: #1976D2; color: #fff; } th, td { padding: 1em .5em; } table tr { color: #212121; } table tr:nth-child(odd) { background-color: #BBDEFB; } Copy after login <div> <table border="0"> <thead> <tr> <th scope="col">head1</th> <th scope="col">head2</th> <th scope="col">head3</th> <th scope="col">head4</th> </tr> </thead> <tbody> <tr> <td>row 1, cell 1</td> <td>row 1, cell 2</td> <td>row 1, cell 2</td> <td>row 1, cell 2</td> </tr> <!-- additional rows omitted for brevity --> </tbody> </table> </div> Copy after login The above is the detailed content of Can CSS Alone Create a Cross-Browser Compatible Scrollable Table with Fixed Headers?. For more information, please follow other related articles on the PHP Chinese website! Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
![]() Hot AI Tools![]() Undresser.AI UndressAI-powered app for creating realistic nude photos ![]() AI Clothes RemoverOnline AI tool for removing clothes from photos. ![]() Undress AI ToolUndress images for free ![]() Clothoff.ioAI clothes remover ![]() AI Hentai GeneratorGenerate AI Hentai for free. ![]() Hot Article
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Assassin's Creed Shadows: Seashell Riddle Solution
2 weeks ago
By DDD
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
![]() Hot Tools![]() Notepad++7.3.1Easy-to-use and free code editor ![]() SublimeText3 Chinese versionChinese version, very easy to use ![]() Zend Studio 13.0.1Powerful PHP integrated development environment ![]() Dreamweaver CS6Visual web development tools ![]() SublimeText3 Mac versionGod-level code editing software (SublimeText3) ![]() Hot Topics
CakePHP Tutorial
![]() ![]() ![]() If you’ve recently started working with GraphQL, or reviewed its pros and cons, you’ve no doubt heard things like “GraphQL doesn’t support caching” or ![]() The Svelte transition API provides a way to animate components when they enter or leave the document, including custom Svelte transitions. ![]() How much time do you spend designing the content presentation for your websites? When you write a new blog post or create a new page, are you thinking about ![]() With the recent climb of Bitcoin’s price over 20k $USD, and to it recently breaking 30k, I thought it’s worth taking a deep dive back into creating Ethereum ![]() npm commands run various tasks for you, either as a one-off or a continuously running process for things like starting a server or compiling code. ![]() The article discusses using CSS for text effects like shadows and gradients, optimizing them for performance, and enhancing user experience. It also lists resources for beginners.(159 characters) ![]() No matter what stage you’re at as a developer, the tasks we complete—whether big or small—make a huge impact in our personal and professional growth. ![]() I was just chatting with Eric Meyer the other day and I remembered an Eric Meyer story from my formative years. I wrote a blog post about CSS specificity, and ![]() |
---|