How to Keep HTML Table Headers Visible While Scrolling the Body?
Dec 09, 2024 am 07:24 AMHow to display scroll bar onto a html table
When creating HTML tables, sometimes it's necessary to have the headers remain visible, even as the table's content scrolls.
To achieve this, wrap the table in a non-statically positioned div that has an overflow:auto CSS property. Then, position the elements in the table head absolutely, as seen below:
#table-wrapper { position:relative; } #table-scroll { height:150px; overflow:auto; margin-top:20px; } #table-wrapper table { width:100%; } #table-wrapper table * { background:yellow; color:black; } #table-wrapper table thead th .text { position:absolute; top:-20px; z-index:2; height:20px; width:35%; border:1px solid red; }
<div>
This will create a table with a fixed header and a scrolling body, similar to method 2 in the provided URL.
The above is the detailed content of How to Keep HTML Table Headers Visible While Scrolling the Body?. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Adding Box Shadows to WordPress Blocks and Elements

Create a JavaScript Contact Form With the Smart Forms Framework

Create an Inline Text Editor With the contentEditable Attribute

Making Your First Custom Svelte Transition

Demystifying Screen Readers: Accessible Forms & Best Practices

Comparing the 5 Best PHP Form Builders (And 3 Free Scripts)

File Upload With Multer in Node.js and Express
