Change the position of a <div> element from relative to absolute:
The position property sets or returns the type of positioning method used for an element (static, relative, absolute or fixed).
The position property is supported in all major browsers.
Return the position property:
Set the position property:
Value | Description |
---|---|
static | Elements renders in order, as they appear in the document flow. This is default. |
absolute | The element is positioned relative to its first positioned (not static) ancestor element |
fixed | The element is positioned relative to the browser window |
relative | The element is positioned relative to its normal position, so "left:20" adds 20 pixels to the element's LEFT position |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
Default Value: | static |
---|---|
Return Value: | A String, representing the position type of an element |
CSS Version | CSS2 |
Using different position types:
Return the position of a <h2> element:
CSS tutorial: CSS Positioning
CSS reference: position property