Reputation: 452
I try to position image between .previewSlide div and .PreviewArrowUl with z-index.
The z-index of .previewSlide is 1, the .PreviewArrowUl is 5 and my img is 20 but PreviewArrowUl is over the img.
.previewSlide {
height: 110px;
background-color: #484848;
z-index: 1;
overflow: hidden;
position: relative;
}
.PreviewArrowUl {
position: absolute;
background: #9b9b9b;
height: 125px;
width: 185px !important;
z-index: 5;
left: 185px;
top: 0px;
background-color: #9b9b9b;
}
.previewSlide ul li img {
width: 155px;
height: 85px;
float: left;
z-index: 20;
position: relative;
}
You can check my example in this JSFiddle.
Anyone have an idea why my image is under the PreviewArrowUl ?
Upvotes: 3
Views: 335
Reputation: 13938
absolute
ly positioned elements shall always overlap the static
ally positioned element (default).
Here the explanation...
The precedence of z-index
is as follows
So when you give any child element a z-index of -1, it won't go below the parents background because of the parents precedence. Also z-index only works on positioned elements. So assigning the z-index to an element without any position assigned (even though defaults to static
) wont have any effect on its position in stack
.
Upvotes: 4