If none of the other elements have a defined z-index
, using z-index: 1
will be fine.
Model: How is the z-index determined?
z-index
<div id=A> Auto 1
<div id=B> Auto 1.1
<div id=C style="z-index:1"></div> Manual 1
<div id=D></div> Auto 1.1.2
</div>
<div id=E></div> Auto 1.2
</div>
<div id=F></div> Auto 2
First, the direct child nodes of the body are walked through. Two elements are encountered: #A and #F. These are assigned a z-index of 1 and 2. This step is repeated for each (child) element in the document.
Then, the manually set z-index
properties are checked. If two z-index
values equal, their position in the document tree are compared.
Your case:
<div id=X style="z-index:1"> Z-index 1
<div id=Y style="z-index:3"></div> Z-index 3
</div>
<div id=Z style="z-index:2"></div> Z-index 2
You'd expect #Y to overlap #Z, because a z-index
of 3 is clearly higher than 2. Well, you're wrong: #Y is a child of #X, with a z-index
of 1. Two is higher than one, and thus, #Z will be shown over #X (and #Y).
The same concept can be easily visualized in this plunker:
http://plnkr.co/edit/CCO4W0NS3XTPsVL9Bqgs?p=preview
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…