Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

z-index not working to get an element above the overlay

I have a horizontal list boxes which is overlapped by a pop up overlay. And horizontal boxes are structured using ui li

Now the question is, how to get the single box above the overlay using z-index. In my example I need to get the li which has class name .test above the overlay div.

.wrapper { position: relative }

ul li {
  margin:0;
  padding:0
}

li {
  background:yellow;
  display:inline-block;
  width:60px;
  height: 60px;

}

.overlay {
  background: rgba(0,0,0,0.5);
  position: fixed;
  top:0;
  left:0;
  width:100%;
  height:100%;
  z-index:10
}

.test {
  z-index:100 /*not working */
}

DEMO

like image 826
Sowmya Avatar asked Sep 02 '25 17:09

Sowmya


2 Answers

z-index property works on positioned elements. You could add position: relative; to the element to get the z-index property to work:

.test {
  z-index:100;
  position: relative;
}

WORKING DEMO

like image 75
Hashem Qolami Avatar answered Sep 05 '25 08:09

Hashem Qolami


Add a position: relative; to your test class

like image 36
Manu Avatar answered Sep 05 '25 07:09

Manu