I'm trying to make a menu bar float constantly at the top of the browser, so when they scroll down the page the menu bar remains at the top.
How could I go about doing this?
Regards,
The CSS tag position: fixed; will make it stay in the same position on the screen, even if scrolling. Use that and then position it with top/right/bottom/left as shown below. z-index will affect how high it is 'stacked'. That is, an element with a z-index of 1 will be beneath an element of a z-index of 100.
div.float {
position: fixed;
top: 10px;
left: 25px;
z-index: 9001;
}
jsfiddle.net was down earlier, but it's back up. Here's an example of a floating menu that is static until you scroll to a certain point: http://jsfiddle.net/2rhrc/
You can do this using the CSS position property. For example:
#menu {
height: 50px;
left: 0;
position:fixed;
top: 0;
}
References:
The first place I noticed this used effectively is on the Perldoc site. If you have to scroll, the #content_header element uses a combination of CSS and JS to keep the element visible on the page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With