Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS to achieve a similar fixed floating div thast always on top of other divs - like stackoverflow does?

I'd like to achieve a similar effect as the one in this image:

enter link description here

Basically, I want to have a div as a menu bar that's always on top - the div beneath it being the container div for my content. Clicking any links in my menu bar only change the content in the container div.

like image 798
Julio Avatar asked Mar 05 '11 19:03

Julio


People also ask

How do I make a div float on top of another div?

You can use the CSS position property in combination with the z-index property to overlay an individual div over another div element. The z-index property determines the stacking order for positioned elements (i.e. elements whose position value is one of absolute , fixed , or relative ).

How do I make DIVs on top of all other controls?

In order to pull an html element out of the natural flow of how the elements are layed out on the screen you need to use position: absolute. This will allow the element to become a layer above the other elements (assuming that the z-index value is greater than all other's).

How do you stack items on top of each other in CSS?

Using CSS position property: The position: absolute; property is used to position any element at the absolute position and this property can be used to stack elements on top of each other. Using this, any element can be positioned anywhere regardless of the position of other elements.

How do I keep my div position fixed?

A pinned-down menu. The interesting rule here is the ' position: fixed ', that makes the DIV stay fixed on the screen. The ' top: 50% ' and ' right: 0 ' determine where the DIV is displayed, in this case: 50% down from the top of the window, and a constant 0px from the right.


1 Answers

You need to use the position: fixed; property for #top div.

<div id="top"></div>

#top {
  position:fixed;
  top:0px;
  width:100%;
  height:70px;
}
like image 121
Hussein Avatar answered Oct 16 '22 09:10

Hussein