CSS2 Test Suite: 9.3.1 position

[index page] [section] [Previous] [Next] [Specification]

The style declarations contained within this page:

.cl1 {position: static; top: -5px; left: 2px;}
.cl2 {position: relative; top: -5px; left: 2px;}
.cl3 {position: absolute; top: 25px; left: 2px;}
.cl4 {position: fixed; top: 0px;  left: 200px;}
.contain {position: relative; background: yellow; height: 50px;}

The following paragraph will contain four positioned images. Each image is prefaced by a class marker, and each image is numbered so that it is possible to determine which images have been positioned in which places. The containing 'p' element has a class of 'contain'. The following is what should happen with each image:

[cl1] image [cl2] image [cl3] image [cl4] image

An excerpt from section 9.3.1:

The 'position' and 'float' properties determine which of the CSS2 positioning algorithms is used to calculate the position of a box.

'position'
Value:  static | relative | absolute | fixed | inherit
Initial:  static
Applies to:  all elements, but not to generated content
Inherited:  no
Percentages:  N/A
Media:  visual

The values of this property have the following meanings:

static
The box is a normal box, laid out according to the normal flow. The 'left' and 'top' properties do not apply.
relative
The box's position is calculated according to the normal flow (this is called the position in normal flow). Then the box is offset relative to its normal position. When a box B is relatively positioned, the position of the following box is calculated as though B were not offset.
absolute
The box's position (and possibly size) is specified with the 'left', 'right', 'top', and 'bottom' properties. These properties specify offsets with respect to the box's containing block. Absolutely positioned boxes are taken out of the normal flow. This means they have no impact on the layout of later siblings. Also, though absolutely positioned boxes have margins, they do not collapse with any other margins.
fixed
The box's position is calculated according to the 'absolute' model, but in addition, the box is fixed with respect to some reference. In the case of continuous media, the box is fixed with respect to the viewport (and doesn't move when scrolled). In the case of paged media, the box is fixed with respect to the page, even if that page is seen through a viewport (in the case of a print-preview, for example).

[index page] [section] [Previous] [Next] [Specification]