I want to be able to apply styles to a “sticky” element when it’s stuck

Submitted by Kalpesh Singh

I had a project where I needed to change background color of a "sticky" element when it moves from being in the normal flow to being "stuck" to the top of the viewport. It’s not possible to do that in CSS. It feels like this should be a pseudo-class (much like :invalid, etc. in forms). Perhaps something like :stuck?

Tagged
CSS