Positioning & Floating

Property: position

Static


selector {
   position: static;
}
				

Relative


selector {
   position: relative;
}
				

Absolute


selector {
   position: absolute;
}
				

Limiting an Absolute Element's Scope

Corral an absolute element inside any non-static element


.container {
   position: relative;
}
.container .foo {
   position: absolute;
   bottom: 10px;
   left: 10px;
   height: 100px;
   width: 100px;
}
				

Positioning in relative

Property: z-index

Since relative- and absolute-positioned elements can overlap, use z-index to control the order of overlapping. The element with the highest z-index goes on top.


selector {
   position: relative;
   z-index: 2;
}
				

Property: float


selector {
   float: left;
   float: right;
}
				

Floating

Property: clear

clear tells the element on which side (left, right, or both) floated elements cannot appear


selector {
   clear: left;
   clear: right;
   clear: both;
}