I have a list of images I\'m trying to overlap so that they look similar to this:
My code:
You can use flex and reverse order then no need z-index:
.avatars {
display: inline-flex;
flex-direction: row-reverse;
}
.avatar {
position: relative;
border: 4px solid #fff;
border-radius: 50%;
overflow: hidden;
width: 100px;
}
.avatar:not(:last-child) {
margin-left: -60px;
}
.avatar img {
width: 100%;
display: block;
}
Here is another idea with scale:
.avatars {
display: inline-block;
transform: scale(-1, 1);
}
.avatar {
position: relative;
display: inline-block;
border: 4px solid #fff;
border-radius: 50%;
overflow: hidden;
width: 100px;
}
.avatar:not(:first-child) {
margin-left: -60px;
}
.avatar img {
width: 100%;
display: block;
transform: scale(-1, 1);
}
Another idea using mask in case you want to keep the order of your images. This will also give you transparency between the images:
.avatar {
display: inline-block;
border-radius: 50%;
overflow: hidden;
width: 100px;
}
.avatar:not(:first-child) {
margin-left: -60px;
-webkit-mask:radial-gradient(circle 55px at 5px 50%,transparent 99%,#fff 100%);
mask:radial-gradient(circle 55px at 5px 50%,transparent 99%,#fff 100%);
}
.avatar img {
width: 100%;
display: block;
}
body {
background:pink
}