Name

top — NN 4 IE 4 CSS 2

Synopsis

Inherited: No

For positionable elements, defines the position of the top edge of an element box (content plus top padding, border, and/or margin) relative to the top edge of the next outermost block content container.

CSS Syntax

top: length | percentage | auto

JavaScript Equivalent

top

Value

See the discussion about length values at the beginning of this chapter. Negative lengths may be allowed in some contexts, but be sure to test the results on all browsers. You may also specify a percentage value, which is calculated based on the height of the next outermost container. The setting of auto lets the browser determine the top offset of the element box on its naturally flowing offset within the containing box.

Initial Value

auto

Example

H1 {position: relative; top: 2em}
#logo {position: absolute; left: 80px; top: 30px}

Applies To

All elements.

Object Model Reference

IE

[window.]document.all.elementID.style.offsetTop

Get Dynamic HTML: The Definitive Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.