Above is a snippet from a html where as I scroll up the header menu gets sticky after JS adds a class active. I was avoiding keyframe animaton so I used above, but
When the menu disappears the disappearnece is not smooth(appearence is smooth), but spontaneous. Is there a way to get this done w/o using keyframes?
I assume that you are talking about after the menu has been shown once and then it hides again?
If so the reason there is no transition is because there is nothing to transition. When you remove the active class there is no position:sticky so top:-100px does nothing at all. If you want a transition back upwards then you will need to have a position:sticky by default.
Now the element will scroll smoothly back to top:-100px.
You would of course need to check that top:100px is taller than the header or you will see the header. It’s probably best if you update that 100px value dynamically with js unless you are certain 100px is enough although rem or em would be better than px.
If I understand correctly then no you can’t omit the gap on one set of elements. You’ll have to use margin instead and then not apply it where you don’t need it.
If you had a small test case demo it might be easier to suggest something else but I’m guessing margins may be the answer.
One way may be to put the first two children in a <div> wrapper so the <div> wrapper becomes the first child of the original parent. The <div> can be flex with no gap. The third child then becomes the second child of the original parent (with a gap). I’m not sure if that’s any better than using margins.