-2

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.

Vaibhav Mule
  • 5,016
  • 4
  • 35
  • 52
danny fox
  • 1
  • 2

1 Answers1

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>

z-index

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