XML technologies / CSS / Advanced websites with CSS / CSS property reference / position
(Excerpt from “CSS − Advanced websites with Cascading Stylesheets” by Rachel Andrew & Dan Shafer)
The property position describes how an element is positioned on the page.
Inherited: no
See also: bottom, left, right, top, z-index
Values
The property is declared with the following constants:
absolute: This setting positions an element at a specified location within its parent element. For example,top: 0andleft: 0place the element in the top-left corner of its nearest ancestor whose propertypositionhas a value other thanstatic. If there is none, it is positioned directly within the elementbody. Elements positioned withabsoluteare removed from an HTML page’s document structure and from the positioning context for other elements on the page.fixed: This setting positions an element in the same way asabsolute. When the page is scrolled, however, the element keeps its position in the browser window rather than moving with the rest of the page.relative: This setting positions an element relative to where it would appear with the settingstatic. For example,top: 30pxandleft: 30pxplace the element 30 pixels below and 30 pixels to the left of its unpositioned location. Elements positioned withrelativeremain part of the positioning context for elements positioned withstaticorabsolute. If elements positioned withabsoluteare aligned with elements positioned withrelative, they too remain within the page’s positioning context.static: This setting positions an element according to the normal document structure. The propertiesbottom,left,rightandtophave no effect.
Default value: static
Compatibility
CSS version: 2
Works in all CSS-capable browsers. However, the setting fixed is implemented correctly only by Mozilla-based browsers (including Netscape version 6 and later), Opera 7 and Internet Explorer 5 for Macintosh. Internet Explorer for Windows (through version 6) interprets fixed in the same way as absolute.
Example
The following style rule positions the element with ID logo 30 pixels from the top and right edges of the browser window. In the positioning context, the element is directly inside the element body. It remains fixed in the browser window even when the user scrolls the page:
#logo {
position: fixed;
top: 30px;
right: 30px;
}
Copyright © 2006 of the German translation, dpunkt.verlag GmbH
You may print the online version for your private use.
Otherwise, this chapter from “CSS − Anspruchsvolle Websites mit Cascading Stylesheets” is subject to the same conditions as the bound edition: the work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
dpunkt.verlag GmbH, Ringstraße 19, 69115 Heidelberg