css - 在两个不同的 div 内的相同位置重叠多个图像

标签 css

我有以下 HTML 代码:

<div id="divFather" class="clsFather">
    <div class="clsSon">
        <img src="A.png">
        <img src="B.png">
    </div>
    <div class="clsSon">
        <img src="A.png">
        <img src="B.png">
    </div>
</div>

这是 .css 文件:

.clsSon{
float: left;
width: 50%;
text-align: center;
position: relative;}

.clsSon img{
position: absolute;
top: 0px;
left: 0px;}

有了这个,我试图在一行中有两个 div,每个 div 中有两个重叠的图像。但取而代之的是,我只在一个地方重叠了四张图片。我想在两个 div 的一行中获得 2 + 2 个重叠图像。我怎样才能得到它?

最佳答案

像这样吗?

.clsSon {
  float: left;
  height: 160px;
  width: 160px;
  text-align: center;
  position: relative;
}

.clsSon img {
  position: absolute;
  top: 0px;
  left: 0px;
}
<div id="divFather" class="clsFather">
    <div class="clsSon">
        <img src="http://source.unsplash.com/160x160">
        <img src="http://source.unsplash.com/160x160/?mountain">
    </div>
    <div class="clsSon">
        <img src="http://source.unsplash.com/160x160">
        <img src="http://source.unsplash.com/160x160/?mountain">
    </div>
</div>

关于css - 在两个不同的 div 内的相同位置重叠多个图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42594901/

相关文章:

html - 使用窄间隙的 Flexbox 将列表拆分为 3 组

html - 选择在模板页面上使用 # vs class

javascript - 如何设置我绘制的 fabricjs 文本对象的一部分?

html - 单页应用的滚动和非滚动版本

asp.net - 使用 HoverMenuExtender 闪烁菜单项

css - Mozilla Firefox 边框渲染

css - Angular 8 - Kendo TextArea 组件中的 formControlName

Jquery Mobile- 页脚元素,100% 宽度

javascript - 在 Yii 上缓存静态文件

javascript - Bootstrap Sidebar 仅在单击两次后打开