Sticky Header Row in Long Tables
Keeps the header row of long tables in posts visible while visitors scroll down through the rows, so they always know which column is which.
Opens WPIDE on
Code
:root {
--wpide-table-top: 0px;
}
.wp-block-table thead th,
.entry-content table thead th {
position: sticky;
top: var(--wpide-table-top);
z-index: 1;
background: var(--wp--preset--color--base, #ffffff);
box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.15);
}
.admin-bar .wp-block-table thead th,
.admin-bar .entry-content table thead th {
top: calc(var(--wpide-table-top) + var(--wp-admin--admin-bar--height, 32px));
}
.wp-block-table:has(thead) {
overflow: visible;
}
Notes
Only works when the table is not inside a horizontally scrolling wrapper. Set --wpide-table-top to your sticky header height.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.