CSS top property

Examples

The upper edge of the image is disposed below the upper edge of its containing element 5 pixels high position:

img
{
position: absolute;
top: 5px;
}


Attribute definitions and instructions

top attribute specifies the top edge of the element. This attribute defines a positioning element of the margin on the border between the block boundary offset its contain.

Relative definitions element, if top and bottom are auto, then the calculated value is 0; if one of them is auto, then take another opposite number value; if neither is auto, bottom will take the top value Opposite number.

Note: If the value is "static" "position" property, then set the "top" property has no effect.

Defaults: auto
inherit: no
version: CSS2
JavaScript syntax: object .style.top = "50px"


Browser Support

Figures in the table represent the first browser to support the version number of the property.

属性
top 1.0 5.0 1.0 1.0 6.0

Property Value

value description
auto Defaults. Calculated on the edge of the browser location.
% Set as a percentage of the containing element meter upper position. You can use a negative value.
length Use px, cm, and other units set top position of the element. You can use a negative value.
inherit Provisions should inherit the value of the top property from the parent element.


related articles

CSS tutorial: CSS Positioning