Click to return to the DHTML, HTML     
toElement Property     top Property     DHTML Properties    
Web Workshop  |  DHTML, HTML & CSS

top Attribute | top Property


Sets or retrieves the position of the object relative to the top of the next positioned object in the document hierarchy.

Syntax

HTML{ top: sTop }
Scriptingobject.style.top [ = sTop ]

Possible Values

sTop String that specifies one of the following values:
autoDefault position according to the regular HTML layout of the page.
lengthFloating-point number, followed by an absolute units designator (cm, mm, in, pt, pc, or px) or a relative units designator (em or ex). For more information about the supported length units, see CSS Length Units.
percentageInteger, followed by a %. This value is a percentage of the height of the parent object.

The property is read/write with a default value of auto; the CSS attribute is not inherited.

Expressions can be used in place of the preceding value(s), as of Microsoft® Internet Explorer 5. For more information, see Dynamic Properties.

Remarks

The top attribute should be used only when the position attribute is set; otherwise, the value of the top attribute is ignored.

Because the value of the top property is a string, you cannot use the property in script to calculate the position of the object in the document; instead, use the pixelTop or the posTop property.

For more information about how to access the dimension and location of objects on the page through the document object model, see Measuring Element Dimension and Location.

Example

The following examples use the top attribute and the top property to change the position of the object.

This example uses an inline style to set the position of a DIV object.

Sample Code

<DIV STYLE="position:absolute;top:100px">
. . . </DIV>

This feature requires Internet Explorer 4.0 or later. Click the icon below to install the latest version. Then reload this page to view the sample.
Microsoft Internet Explorer

This example uses inline script to change the position of the image set by an inline style. The change occurs during onmouseover and onmouseout events.

<IMG SRC="cone.jpg" STYLE="position:absolute; 
    top:80px;" onmouseover="this.style.top='100px''"    
    onmouseout="this.style.top='80px'" >

This feature requires Internet Explorer 4.0 or later. Click the icon below to install the latest version. Then reload this page to view the sample.
Microsoft Internet Explorer

Applies To

[ Object Name ]
PlatformVersion
Win16:
Win32:
Mac:
Unix:
WinCE:
A, ADDRESS, APPLET, B, BIG, BLOCKQUOTE, BUTTON, CENTER, CITE, CODE, currentStyle, custom, DD, DFN, DIR, DIV, DL, DT, EM, EMBED, FIELDSET, FORM, Hn, HR, I, IFRAME, IMG, INPUT type=button, INPUT type=checkbox, INPUT type=file, INPUT type=image, INPUT type=password, INPUT type=radio, INPUT type=reset, INPUT type=submit, INPUT type=text, ISINDEX, KBD, LABEL, LEGEND, LI, LISTING, MARQUEE, MENU, OBJECT, OL, P, PRE, runtimeStyle, S, SAMP, SELECT, SMALL, SPAN, STRIKE, STRONG, style, SUB, SUP, TABLE, TEXTAREA, TT, U, UL, VAR, XMP

See Also

pixelTop, posTop



Back to topBack to top

Did you find this topic useful? Suggestions for other topics? Write us!

© 1999 Microsoft Corporation. All rights reserved. Terms of use.