Reputation: 4861
How can I have 4 images where the first image has the highest z-index, and the next the second highest (i'm also open to other suggestions as to how to accomplish this)? Basically reverse the following depth?
img {
display: inline;
margin-right: -40px;
border-radius: 50%;
}
div:nth-child(1) {
z-index: 1000;
}
<div>
<img src="http://via.placeholder.com/100x100">
<img src="http://via.placeholder.com/100x100/000">
<img src="http://via.placeholder.com/100x100">
<img src="http://via.placeholder.com/100x100/000">
</div>
Upvotes: 2
Views: 504
Reputation: 5648
To use z-index
as expected, you'll need to set the <img>
position to relative.
Also the nth-child
has to be of set to the <img>
tag
Hope this is what you were looking for. Happy to explain or help in a better solution if needed.
img {
display: inline;
position: relative;
margin-right: -40px;
border-radius: 50%;
}
div img:nth-child(1) {
z-index: 3;
}
div img:nth-child(2) {
z-index: 2;
}
div img:nth-child(3) {
z-index: 1;
}div img:nth-child(4) {
z-index: 0;
}
<div>
<img src="http://via.placeholder.com/100x100">
<img src="http://via.placeholder.com/100x100/000">
<img src="http://via.placeholder.com/100x100">
<img src="http://via.placeholder.com/100x100/000">
</div>
Upvotes: 3