Z-Index:

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.

An Example

The following example comes from an article on the Mozilla Developers Network.

Notice a few things about this example.

  1. DIV #1 was given a position value of absolute and z-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.
  2. Likewise, DIV #4 is also placed on top of the yellow DIV #5 element.
  3. The green DIV #2 is placed on top of DIV #4 since it has a higher z-index, but underneath DIV #1.
  4. The blue, DIV #3 was placed underneath all other elements, even the yellow DIV #5.
    • This is because it was given a negative z-index (-2).
    • This allows it to be placed under DIV #3, even though DIV #3 cannot be placed above other elements with position values specified.

{ TODO: }

Read page 369 of Chapter 15 in Duckett.


Previous section:
Next section: