Class Act

Back to the shelf

CSS · Snippet · ASP.net

position sticky table header

CSS to keep a table header row sticky at the top while the body rows scroll underneath it.

Example

How to use position sticky table header:
Paste the rules into the stylesheet and reload the page that should use them.

Notes

A parent element with overflow:hidden stops sticky from working. The th needs a background color or rows will show through it while scrolling. Use z-index to keep the header on top.

Code

.grid thead th {
    position: sticky;
    top: 0;
    background: #fff;
    z-index: 1;
}