XML technologies / CSS / Advanced websites with CSS / CSS property reference / z-index

(Excerpt from “CSS − Advanced websites with Cascading Stylesheets” by Rachel Andrew & Dan Shafer)

The property z-index describes the position of an element not positioned with static in a stack of overlapping elements.

Elements positioned with static or not positioned at all are always below elements positioned with absolute or relative within the same stacking context. Their z-index is 0. Elements in the same stacking context with equal values of z-index are stacked in HTML source order, the first at the bottom and the last at the top.

Inherited: no

See also: position

Value

A positive integer or the constant auto. Higher numeric values place the element higher in the stack.

With the constant auto the element behaves as if it had a z-index of 0. It does not create a new stacking context, but joins an existing one at the lowest position.

Default value: auto

Compatibility

CSS version: 2

Works in all CSS-capable browsers, including Netscape 4.

Example

The following rule positions the element with the ID hauptmenue ten pixels from the browser window’s top-left corner. If elements overlap, its z-index makes it float above elements with a lower z-index:

#hauptmenue {
 position: absolute;
 top: 10px;
 left: 10px;
 width: 100px;
 height: 300px;
 z-index: 10;
}

  

 

 

 

back to top