I have a HTML and CSS bar which is added to the top of a site, and need some code to keep it at the top when scrolling down.
I would be preferably using JavaScript, or anything that works, I just need something to keep it at the top.
Help is appreciated!
Check out this site for what I am looking for – http://9gag.com/
9gag.com also uses
position:fixed;for the header, but in your case, it’s making itposition:fixed !importantis the solution, since it’s overridden below where you’ve put it on your site (at the top).CSS:
Live demo | Demo source
Edit:
The easiest way to achieve this without sacrificing the suckerfish position is to use jQuery, as you’ve mentioned
Live demo | Demo source
It works, however it’s incredibly glitchy; just set netbar to absolute again by removing the
#netbar{position:fixed !important;}line from your siteOr if you’re willing to sacrifice the suckereye’s position for a little less glitchy-ness, use this code instead:
The enjin-bar is not a part of the netbar and that’s the main reason why it doesn’t follow the netbar when you scroll, so the easiest way to bypass this is to use jQuery
Live demo | Demo source
Edit2:
Replace the code from the pastie to the one below: