【发布时间】:2018-08-01 15:43:26
【问题描述】:
我有一个我试图重叠的图像列表,以便它们看起来类似于:
我的代码:
.avatar img {
border-radius: 50%;
position: relative;
left: -5px;
z-index: 1;
}
<div class="avatars">
<span class="avatar">
<img src="https://picsum.photos/70" width="25" height="25"/>
</span>
<span class="avatar">
<img src="https://picsum.photos/50" width="25" height="25"/>
</span>
<span class="avatar">
<img src="https://picsum.photos/20" width="25" height="25"/>
</span>
<span class="avatar">
<img src="https://picsum.photos/100" width="25" height="25"/>
</span>
<!-- Variable amount more avatars -->
</div>
<p>4 People</p>
但显然,我需要一个递增的left 值,以及一个递减的z-index 用于头像img 的数量。当然,我可以使用@for 指令来做到这一点,但问题是,头像图像的数量是可变的。我正在查看 length() 函数,但它并不能像我打算使用的那样工作。
另一个想法是设置一个宽度 div,并在其中放置图像,但这有其自身的问题(如果有 5 个图像或 20 个图像,如何控制宽度)。我还可以在其他地方按我想要的方式组合图像,而不使用任何 CSS。
【问题讨论】:
标签: html css sass z-index overlap