Z-Index in Practice
The following example comes from an article on the Mozilla Developers Network.
Notice a few things about this example.
DIV #1was given a position value ofabsoluteandz-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 #4is also placed on top of the yellowDIV #5element. - The green
DIV #2is placed on top ofDIV #4since it has a higher z-index, but underneathDIV #1. - The blue,
DIV #3was 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 #3cannot be placed above other elements with position values specified.
- This is because it was given a negative z-index (