Freigeben über


position property

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

 

Syntax

Integer value = object.put_position( v);Integer value = object.get_position(* sPosition);

Property values

Type: BSTR

static (static)

Default. Object has no special positioning; it follows the layout rules of HTML.

absolute (absolute)

Object is positioned relative to parent element's position—or to the body object if its parent element is not positioned—using the IHTMLCSSStyleDeclaration::top and IHTMLCSSStyleDeclaration::left properties.

relative (relative)

Object is positioned according to the normal flow, and then offset by the IHTMLCSSStyleDeclaration::top and IHTMLCSSStyleDeclaration::left properties.

fixed (fixed)

Starting in Internet Explorer 7. Object is positioned relative to the layout viewport containing the content. Its positioning and display are unaffected by user panning, but affected by user zooming actions.

page (page)

Internet Explorer 10. Positioned floats only. (The IHTMLCSSStyleDeclaration::display property must be set to -ms-positioned.) Object is positioned relative to the nearest initial containing block. This may be the browser or application window or a content container such as an iframe. The IHTMLCSSStyleDeclaration::bottom, IHTMLCSSStyleDeclaration::top, IHTMLCSSStyleDeclaration::left, and IHTMLCSSStyleDeclaration::right properties are used to position the element relative to the boundaries of the viewport that the positioned float would normally be placed in (that is, if position:static was set). For more information, see Positioned Floats.

-ms-device-fixed

IE11. Object is positioned relative to the visual viewport containing the content. Its positioning and display are unaffected by user panning actions as well as user zooming actions.

String format

static | relative | absolute | fixed | page | -ms-device-fixed

CSS information

Applies To All elements
Media visual
Inherited no
Initial Value static

Standards information

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 IHTMLCSSStyleDeclaration::zIndex 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 IHTMLCSSStyleDeclaration::top, IHTMLCSSStyleDeclaration::bottom, IHTMLCSSStyleDeclaration::left, or IHTMLCSSStyleDeclaration::right properties, in addition to setting the IHTMLCSSStyleDeclaration::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 IHTMLCSSStyleDeclaration::overflow property is set to auto or scroll).
  • The parent is positioned (that is, its IHTMLCSSStyleDeclaration::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 &quot;xyz&quot;.</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 IHTMLCSSStyleDeclaration::height and IHTMLCSSStyleDeclaration::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 IHTMLCSSStyleDeclaration::width.

Starting in Internet Explorer 7. Fixed positioning is only supported for pages using a strict IHTMLDocument5::doctype.

For an overview about how to use dynamic positioning, see About Element Positioning.

Examples

The following example shows how to use the IHTMLCSSStyleDeclaration::position property to specify absolute or relative positioning of objects. The example shows two pairs of boxes. In the first pair of boxes, the IHTMLCSSStyleDeclaration::position property is set to absolute and the boxes overlap. In the second pair of boxes, the IHTMLCSSStyleDeclaration::position property is set to relative and the boxes are positioned relative to each other.

div {
  width: 80px;
  height: 80px;
}
.redbox1 {
  position: absolute;
  background-color: red;
  top: 20px;
  left: 20px;
}
.bluebox1 {
  position: absolute;
  background-color: lightblue;
  top: 40px;
  left: 40px;
}
.redbox2 {
  position: relative;
  background-color: red;
  top: 20px;
  left: 140px;
}
.bluebox2 {
  position: relative;
  background-color: lightblue;
  top: 40px;
  left: 160px;
}
<body>
  <div class="redbox1"></div>
  <div class="bluebox1"></div>
  <div class="redbox2"></div>
  <div class="bluebox2"></div>
</body>

The following image shows the result:

Requirements

Minimum supported client

Windows 2000 Professional, Windows XP

Minimum supported server

Windows Server 2003

Header

Mshtml.h

IDL

Mshtml.idl

DLL

Mshtml.dll