niutech
niutech

Reputation: 29942

Why a div with higher z-index is not visible (covered)?

In this example an inner green div is covered by a middle blue div, at least in Chrome, despite that it has a higher z-index. Why is it so and how to make it visible over the blue div? The green div must be inside an outer yellow div. From the top:

1. #inner
2. #middle
3. #outer

Upvotes: 0

Views: 3427

Answers (1)

Vitorino fernandes
Vitorino fernandes

Reputation: 15971

you could achieve that but you will need to move the #middle div inside #outer for the z-index to work

div {
  position: absolute;
}
#outer {
  width: 300px;
  height: 100px;
  top: 20px;
  background: yellow;
}
#inner {
  width: 240px;
  height: 80px;
  top: 10px;
  left: 30px;
  background: green;
  z-index: 2;
}
#middle {
  width: 280px;
  height: 140px;
  left: 10px;
  z-index: 1;
  background: blue;
  top: -16px;
}
<div id="outer">
  <div id="inner"></div>
  <div id="middle"></div>
</div>

Upvotes: 4

Related Questions