I'm learning web design. I don't know z-index and what is it used for... I'm trying to positioning a drop down menu. I read it can be useful for menu in a book. so I'll be thankful if someone answer me.
Asked
Active
Viewed 527 times
-2
-
3https://css-tricks.com/almanac/properties/z/z-index/ this should be helpful – Vlad May 26 '15 at 07:49
-
you can think of z-index property like the tool that move layers forward or backwards in illustrator – maioman May 26 '15 at 07:51
1 Answers
0
You can always check the docs:
The z-index property specifies the z-order of an element and its descendants. When elements overlap, z-order determines which one covers the other. An element with a larger z-index generally covers an element with a lower one.
For a positioned box, the z-index property specifies:
The stack level of the box in the current stacking context.
List item Whether the box establishes a local stacking context.
Example:
.dashed-box {
position: relative;
z-index: 1;
border: dashed;
height: 8em;
margin-bottom: 1em;
margin-top: 2em;
}
.gold-box {
position: absolute;
z-index: 3;
/* put .gold-box above .green-box and .dashed-box */
background: gold;
width: 80%;
left: 60px;
top: 3em;
}
.green-box {
position: absolute;
z-index: 2;
/* put .green-box above .dashed-box */
background: lightgreen;
width: 20%;
left: 20em;
top: -25px;
height: 7em;
opacity: 0.9;
}
<div class="dashed-box">Dashed box
<span class="gold-box">Gold box</span>
<span class="green-box">Green box</span>
</div>

Alex Char
- 32,879
- 9
- 49
- 70