HBCMS更多的中文手册参考:

position Attribute | position参数属性

DHTML文档教程

Sets or retrieves the type of positioning used for the object.

dhtml语法

HTML { position : sPosition }
Scriptingobject.style.position [ = sPosition ]

DHTML可能的值

sPositionString that specifies or receives one of the following values.
staticDefault. Object has no special positioning; it follows the layout rules of HTML.
absoluteObject is positioned relative to parent element's position—or to the body object if its parent element is not positioned—using the top and left properties.
relativeObject is positioned according to the normal flow, and then offset by the top and left properties.

The property is read/write for all objects except the following, for which it is read-only: currentStyle. The property has a default value of static. The Cascading Style Sheets (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 about dynamic properties.

remarks

setting the property to absolute pulls the object out of the "flow" of the document and positions it regardless of the layout of surrounding objects. if other objects already occupy the given position, they do not affect the positioned object, nor does the positioned object affect them. instead, all objects are drawn at the same place, causing the objects to overlap. this overlap is controlled by using the z-index attribute or property. absolutely positioned objects do not have margins, but they do have borders and padding.

to enable absolute positioning on an object you must specify at least one of the top, bottom, left, or right properties, in addition to setting the position property to absolute. otherwise, these positioning properties use their default value of absolute, which causes the object to render immediately after the preceding elements, according to the layout rules of html.

input from pointing devices, such as the mouse, does not penetrate through overlapping elements even if the elements are not visible. this is also true for positioned elements with a negative z-index unless:

  • the parent is a scrolling container (that is, its overflow property is set to auto or scroll).
  • the parent is positioned (that is, its position property is set to absolute or relative).

setting the property to relative places the object in the natural html flow of the document, but offsets the position of the object based on the preceding content. the following syntax shows how to create superscript text by placing the text in a span that is positioned relative to the remaining text in the paragraph.

<P>The superscript in this name
<SPAN STYLE="position:relative;
top:-3px">xyz </SPAN> is "xyz".</P>

Text and objects that follow a relatively positioned object occupy their own space and do not overlap the natural space for the positioned object. In contrast, text and objects that follow an absolutely positioned object occupy what would have been the natural space for the positioned object before it was pulled out of the flow. Placing an absolutely positioned object beyond the viewable area of the window causes a scroll bar to appear. When relatively positioned objects are placed beyond the viewable area, a scroll bar is not shown.

The size of the content determines the size of objects with layout. For example, setting the height and position properties on a div object gives it layout. the content of the div determines the size. in this case, the content determines the size of the width.

for an overview about how to use dynamic positioning, see about element positioning.

see the applies to section for elements that can be relatively and absolutely positioned.

DHTML代码范例

This examples uses the position property's absolute, static, and relative values to change the position of the text.

<STYLE>
.pitem { position: static }
</STYLE>
<SCRIPT>
function fnAbsolute(){
oSpan.style.position="absolute";
}
function fnRelative(){
oSpan.style.position="relative";
}
function fnStatic(){
oSpan.style.position="static";
}
</SCRIPT>
<P>
<SPAN ID=oSpan CLASS="pitem">
This is a SPAN in a paragraph of text.
</SPAN>
This is a paragraph of text.</P>
<INPUT onclick="fnRelative()" TYPE=button VALUE="Relative">
<INPUT onclick="fnAbsolute()" TYPE=button VALUE="Absolute">
<INPUT onclick="fnStatic()" TYPE=button VALUE="Static">
This feature requires Microsoft® Internet Explorer 4.0 or later. Click the following icon to install the latest version. Then reload this page to view the sample.

是否符合公共标准

This property is defined in Cascading Style Sheets (CSS), Level 2 (CSS2) Non-Microsoft link.

Applies To

A, ADDRESS, APPLET, B, BDO, BIG, BLOCKQUOTE, BUTTON, CENTER, CITE, CODE, currentStyle, CUSTOM, DD, defaults, DFN, DIR, DIV, DL, DT, EM, EMBED, FIELDSET, FONT, 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, RUBY, runtimeStyle, S, SAMP, SELECT, SMALL, SPAN, STRIKE, STRONG, style, SUB, SUP, TABLE, TD, TEXTAREA, TH, TR, TT, U, UL, VAR, XMP