Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
148
rated 0 times [  153] [ 5]  / answers: 1 / hits: 18671  / 8 Years ago, thu, june 30, 2016, 12:00:00

Let's take take a simple example:



<nav id=#mynav>MY NAVBAR</nav>


and a basic style:



#mynav {
position : sticky;
}


I would like to apply the following styling information to my navbar only when it detaches from the normal flow, in order to visually split it from the main content (with a shadow in this case)



box-shadow : 0px 10px 15px 0px rgba(0,0,0,0.75);


Is there some kind of pseudo-class or media-query-like thing I could use for that? E.g.:



#mynav:some-pseudo-class {
box-shadow : 0px 10px 15px 0px rgba(0,0,0,0.75);
}


I know there are good plugins for this, but all of them seem to be unable to implement it whithout bypassing the (quite new) native feature position:sticky. Instead, they do it in an old-fashion way (scroll event, and position:fixed; top:0).



So, is it possible to do it using position:sticky, and without using the scroll event, which slows down the fluidity of the page (I'm not against javascript, but scroll event is too slow)?


More From » css

 Answers
8

Unfortunately, as far as I know there are no pseudo class that targets the 'sticky' state.


See post: Targeting position:sticky elements that are currently in a 'stuck' state


An alternative would be to use jQuery to add or remove a class/css styling when it reaches the element that needs to be stickied.


[#61567] Tuesday, June 28, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
nora

Total Points: 248
Total Questions: 111
Total Answers: 97

Location: India
Member since Wed, Aug 4, 2021
3 Years ago
nora questions
Tue, Nov 3, 20, 00:00, 4 Years ago
Wed, Sep 9, 20, 00:00, 4 Years ago
Mon, Jun 15, 20, 00:00, 4 Years ago
Wed, May 13, 20, 00:00, 4 Years ago
;