Gets or sets the type of positioning used for the object.
HRESULT IHTMLStyle2::get_position(BSTR *p);HRESULT IHTMLStyle2::put_position(BSTR v);
- Pointer to a variable of type BSTR that receives one of the values listed in Possible Values.
- BSTR that specifies one of the values listed in Possible Values.
static Default. Object has no special positioning; it follows the layout rules of HTML. absolute Object is positioned relative to parent element's position—or to the body object if its parent element is not positioned—using the IHTMLStyle::top and IHTMLStyle::left properties. relative Object is positioned according to the normal flow, and then offset by the IHTMLStyle::top and IHTMLStyle::left properties. fixed Windows Internet Explorer 7 and later. Object is positioned relative to the viewport containing the content.
Returns S_OK if successful, or an error value otherwise.
Setting the property to
absolutepulls 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 IHTMLStyle::top, IHTMLStyle2::bottom, IHTMLStyle::left, or IHTMLStyle2::right properties, in addition to setting the IHTMLStyle2::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
- The parent is positioned (that is, its IHTMLStyle2::position property is set to
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 IHTMLStyle::height and IHTMLStyle2::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 IHTMLStyle::width.
For an overview about how to use dynamic positioning, see About Element Positioning.