CSS top Property
CSS top
property specifies the top position of an element in combination with the position property.
If position: absolute;
or position: fixed;
: The top
property sets the top position of an element to a unit above/below the top position of its nearest positioned ancestor.
Usages
The following table outline the usages and version history of this property.
Default value: | auto |
Applies to: | Positioned elements |
Inherited: | No |
Version: | CSS2 |
JavaScript Syntax: | object.style.top = "15px" |
Syntax
Here is a syntax for the CSS top
property
top: auto | length | percentage | initial | inherit;
Property Values
The following table describes the values of this property.
Value | Description |
---|---|
auto | Default. Browser will calculate the top position for the element |
length | Specifies the length value expressed in px, pt, cm, em, etc. to set top position Negative values are allowed. |
percentage | Specifies the percentage value to set top position |
initial | Sets default value of this property |
inherit | Inherits this property from its parent element |
Examples
The example below shows to sets top property.
div.one {
top: 10%;
position: absolute;
}
div.two {
top: 0;
position: absolute;
}
Browser Compatibility
- Google Chrome 1+
- Mozilla Firefox 1+
- Internet Explorer 5+
- Opera 6+
- Safari 1+
Note: Here details of browser compatibility with version number may be this is bug and not supported. But recommended to always use latest Web browser.