Z-Index in Practice
The following example comes from an article on the Mozilla Developers Network.
Notice a few things about this example.
DIV #1
was given a position value ofabsolute
andz-index: 5
.- This is causing it to be placed on top of all other elements.
- Even the yellow element
DIV #5
. That is because the yellow element did not have a position property setting.
- Likewise,
DIV #4
is also placed on top of the yellowDIV #5
element. - The green
DIV #2
is placed on top ofDIV #4
since it has a higher z-index, but underneathDIV #1
. - The blue,
DIV #3
was placed underneath all other elements, even the yellowDIV #5
.- This is because it was given a negative z-index (
-2
). - This allows it to be placed under
DIV #3
, even thoughDIV #3
cannot be placed above other elements with position values specified.
- This is because it was given a negative z-index (
- Previous
- Next