# Stacking Objects (3D Positioning)

Although the screen is a two-dimensional area, elements that are positioned can be given a third dimension: a stacking order in relationship to one another.

Positioned elements are assigned stacking numbers automatically, starting with 0 and continuing incrementally with 1, 2, 3, and so on, in the order in which the elements appear in the HTML and relative to their parents and siblings. Elements with higher numbers appear above those with lower numbers. This system is called the z-index (Table 7.4). An element's z-index number is a value that shows its 3D relationship to other elements in the document or parent element.

##### Table 7.4. Z-Index Values

VALUE

COMPATIBILITY

<number>

IE4, FF1, S1, O3.5, CSS2

auto

IE4, FF1, S1, O3.5, CSS2

If the content of elements overlap each other, the element with a higher number in the stacking order appears over the element that has a lower number.

You can override the natural order of the z-index (Figures 7.7 and 7.8) by setting a value for the z-index property.

##### Figure 7.8. With the z-index set in the code, the stacking order is changed. Notice that although Object 1 should be on the bottom of the stack, its z-index has been set to 3, so it appears on top.

To define an element's z-index:

1.

`position: absolute;`

To layer an element in the window, you have to define the position property (Code 7.4).

##### Code 7.4. In the code, positioned elements appear stacked on top of each other based on their order in the HTML code. Using the z-index property, you can override that natural stacking order to put whatever you want on top.

 [View full width]` CSS, DHTML & Ajax | Stacking Elements On Top of Each Other
Object 1
Object 2
Object 3
Object 4
`

(See "Setting the Positioning Type" earlier in this chapter for more information.)

2.

`z-index:`

Type the z-index property name, followed by a colon (:), in the same declaration block.

3.

`3;`

Now type a positive or negative number (no decimals allowed), or 0. This step sets the element's z-index in relation to its siblings, where 0 is on the same level.

Alternatively, type auto to allow the browser to determine the element's z-index order.

Tips

• Using a negative number for the z-index causes an element to be stacked that many levels below its parent instead of above.

• You can change the stacking order of elements using JavaScript (see "Moving Objects in 3D" in Chapter 16).

CSS, DHTML, and Ajax, Fourth Edition
ISBN: 032144325X
EAN: 2147483647
Year: 2006
Pages: 230

Similar book on Amazon