Why is z-index ignored with position:static?

ripper234 picture ripper234 · Dec 13, 2011 · Viewed 16.1k times · Source

See this comment from jquery-ui

// Ignore z-index if position is set to a value where z-index is ignored by the browser
// This makes behavior of this function consistent across browsers
// WebKit always returns auto if the element is positioned

I see that jquery's zIndex() returns 0 if the element is position: static.

Isn't z-index supported on position:static? (It works for me in Chrome, haven't tested cross-browser)

Answer

Quentin picture Quentin · Dec 13, 2011

Because position: static means "Ignore all the positioning instructions from left, top, z-index, etc.".

'z-index'
Value:      auto | <integer> | inherit
Initial:    auto
Applies to:     positioned elements

http://www.w3.org/TR/CSS21/visuren.html#z-index

An element is said to be positioned if its 'position' property has a value other than 'static'.

http://www.w3.org/TR/CSS21/visuren.html#positioned-element