DEV Community

Discussion on: Applying Styles Based on the User Scroll Position with Smart CSS

Collapse
 
link2twenty profile image
Andrew Bone • Edited

You can use position:sticky; to save a little bit of code too.

Collapse
 
rikschennink profile image
Rik Schennink

Nice, Thanks Andrew!

Just checked sticky browser support and it's actually quite great.

Sticky Browser Support Table

I also noticed the demo didn't work on Safari, it seems it still needs the -webkit- prefix.

header {
  position: sticky;
  position: -webkit-sticky;
}