CSS top property
Set the top edge of an image 5 pixels high below the top edge of its containing element:
{
position:absolute;
top:5px;
}
Try it out . . .
Description of property definition and use
The top property specifies the top edge of the element. This property defines the offset between the top margin boundary of a positioning element and the upper boundary of its containing block.
For relatively defined elements, if both top and bottom are auto, the calculated values are 0, if one of them is auto, the opposite number of the other value, and if neither is auto, bottom will take the opposite number of the top value.
Note: If the value of the "position" property is "static," setting the "top" property will have no effect.
Default: | auto |
---|---|
Inherited: | no |
Version: | CSS2 |
JavaScript syntax: | object .style.top="50px" |
Browser support
The numbers in the table support the first browser version number of the property.
Attributes | |||||
---|---|---|---|---|---|
top | 1.0 | 5.0 | 1.0 | 1.0 | 6.0 |
The property value
Value | Describe |
---|---|
auto | The default. The position of the upper edge is calculated from the browser. |
% | Sets the top position as a percentage of the contained elements. Negative values can be used. |
length | Use units such as px, cm to set the top position of the element. Negative values can be used. |
inherit | Specifies that the value of the top property should be inherited from the parent element. |
Related articles
CSS tutorial: CSS Positioning