On the last page, we learned how to place elements “wherever” we want. We even learned how to place elements over other elements, thereby, blocking those elements.
The z-index property allows developers to specify which elements should be placed on top of other elements. The z-index property takes an integer number as its value (i.e. -1000 to 1000). Those elements with higher z-index values will be drawn on top elements with lower values.
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 of absolute
and z-index: 5
.
DIV #5
. That is because the yellow element did not have a position property setting.DIV #4
is also placed on top of the yellow DIV #5
element.DIV #2
is placed on top of DIV #4
since it has a higher z-index, but underneath DIV #1
.DIV #3
was placed underneath all other elements, even the yellow DIV #5
.
-2
).DIV #3
, even though DIV #3
cannot be placed above other elements with position values specified.Read page 369 of Chapter 15 in Duckett.