Fixed Positioning
An element with fixed position is positioned relative to the browser window.
It will not move even if the window is scrolled:
Example
|
Note: IE7 and IE8 support the fixed value only if a !DOCTYPE is specified.
Fixed positioned elements are removed from the normal flow. The document and other elements behave like the fixed positioned element does not exist.
Fixed positioned elements can overlap other elements.
Relative Positioning
A relative positioned element is positioned relative to its normal position.
Example
The content of relatively positioned elements can be moved and overlap other elements, but the reserved space for the element is still preserved in the normal flow. |
Example
|
Relatively positioned elements are often used as container blocks for absolutely positioned elements.
Absolute Positioning
An absolute position element is positioned relative to the first parent element that has a position other than static. If no such element is found, the containing block is <html>:
Example
|
Absolutely positioned elements are removed from the normal flow. The document and other elements behave like the absolutely positioned element does not exist.
Absolutely positioned elements can overlap other elements.
Overlapping Elements
When elements are positioned outside the normal flow, they can overlap other elements.
The z-index property specifies the stack order of an element (which element should be placed in front of, or behind, the others).
An element can have a positive or negative stack order:
Example
|
CSS Positioning Properties
The number in the "CSS" column indicates in which CSS version the property is defined (CSS1 or CSS2).
Property | Description | Values | CSS |
---|---|---|---|
bottom | Sets the bottom margin edge for a positioned box | auto length %inherit | 2 |
clip | Clips an absolutely positioned element | shapeauto inherit | 2 |
cursor | Specifies the type of cursor to be displayed | urlauto crosshair default pointer move e-resize ne-resize nw-resize n-resize se-resize sw-resize s-resize w-resize text wait help | 2 |
left | Sets the left margin edge for a positioned box | auto length %inherit | 2 |
overflow | Specifies what happens if content overflows an element's box | auto hidden scroll visible inherit | 2 |
position | Specifies the type of positioning for an element | absolute fixed relative static inherit | 2 |
right | Sets the right margin edge for a positioned box | auto length %inherit | 2 |
top | Sets the top margin edge for a positioned box | auto length %inherit | 2 |
z-index | Sets the stack order of an element | numberauto inherit | 2 |