Border style do not work with sticky position element
⚡TLDR
Apply a pseudo-element as a workaround to persist the border of a sticky element.
Handling borders on sticky table headers
The table layout
To prevent sticky table headers from hiding or overlapping borders:
- Utilize
border-collapse: separate;
on the table. - Make the borders prominent using
border-top
andborder-bottom
on<th>
elements. - In lieu of borders, consider using
box-shadow
as a border substitute.
Code insights
Border Control: The Advanced Level
The box-shadow styling
Use box-shadow
to create cool border effects on sticky table headers and cells.
Tackling browser-specific inconsistencies
For browsers like Firefox, where sticky positioning behaves weirdly, consider specific fixes like empty pseudo-elements and adjustments on background
.
Crafty use of pseudo-elements
Create complex border effects using ::before
or ::after
pseudo-classes in tandem with absolute positioning.
Preserving borders during scrolls
If scroll interactions cause borders to vanish, use alternatives like outline
and box-shadow
to maintain the visual persistence of borders.
Linked
Was this article helpful?