Sticky headers and stacking in CSS
Sticky sits between relative and fixed; z-index orders what overlaps.
.site-header {
position: sticky;
inset-block-start: 0;
z-index: 10;
backdrop-filter: blur(8px);
}
thead th {
position: sticky;
inset-block-start: 0;
background: #0b0c10;
}
.card {
isolation: isolate;
}
How it works
- A sticky box needs an inset and a scrolling ancestor to stick to.
z-indexonly applies to positioned or flex and grid children.isolation: isolatekeeps a component's stacking to itself.
Keywords and builtins used here
backgroundblurcardisolationpositionpx
The run, in numbers
- Lines
- 16
- Characters to type
- 203
- Tokens
- 48
- Three-star pace
- 85 tpm
At the three-star pace of 85 tokens a minute, this run takes about 34 seconds.
Step 3 of 7 in Positioning, step 19 of 24 in Flexbox & grid.