XML technologies / CSS / Advanced websites with CSS / CSS property reference / top

(Excerpt from “CSS − Advanced websites with Cascading Stylesheets” by Rachel Andrew & Dan Shafer)

The property top determines the distance between the top edge of an element positioned with absolute, including padding, border and margin, and the top edge of its positioning group. (The CSS2 specification incorrectly says that padding, border and margin should be disregarded here; the CSS Working Group has documented this error in the CSS2 errata.) The element is aligned to the nearest ancestor whose property position has a value other than static. If no such ancestor exists, it is aligned to the element body.

When positioning is calculated from the element body, Internet Explorer for Windows, Netscape 6 and Mozilla position the element relative to the top of the browser window (before scrolling), rather than the top of the entire document as CSS specifies. Internet Explorer 5 for Macintosh correctly positions relative to body.

For elements positioned with the value relative, the property top shifts the element relative to its position without CSS positioning. For example, 10px moves it 10 pixels down, while -10px moves it up.

Inherited: no

See also: position, bottom, left, right

Values

A CSS measurement, a percentage of the parent element’s height, or the constant auto. The constant auto lets the browser determine the position, taking other variables such as size and position into account.

Default value: auto

Compatibility

CSS version: 2

Works in all CSS-capable browsers, including Internet Explorer 4 and later, Netscape 4 and later, and Mozilla.

Example

The following style rule places the element with ID menue ten pixels from the browser window’s top edge:

#menue {
 position: absolute;
 top: 10px;
}

  

 

 

 

back to top