html - 位置绝对重叠的两个 div
问题描述
我对 css 完全陌生,想创建两个绝对位置的 div。这是CSS:
.divcontent {
position: absolute;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
width: 100%;
bottom: 5%;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
z-index: 2;
opacity: .8
}
.divcontent span {
font-size: 0.875rem;
color: #4D575D;
margin: 0 3px
}
这是html:
<div id="div1" class="divcontent">
<span>Some text</span>
</div>
<div id="div2" class="divcontent">
<span>Some other text</span>
</div>
现在这两个 div 相互重叠。我想将 div2 放在 div1 的底部
解决方案
它不能这样做,因为position: absolute
它旨在允许您为元素指定绝对位置。
您可以使用其中一个top
或bottom
与成员元素一起相应地放置它。
<div id="div1" class="divcontent">
<span>Some text</span>
</div>
<div id="div2" class="divcontent" style="bottom: 5px;">
<span>Some other text</span>
</div>
如果你想要它有点通用,那么创建一个 CSSpadding-bottom-05 { padding-bottom: 5px; }
然后用html
<div id="div2" class="divcontent padding-bottom-05">
推荐阅读
- python - 调用 C++ 代码时,如何防止 python 中出现特定于平台的 ValueError?
- amazon-s3 - 如何使用 ACL 在 S3 上托管静态网站?
- scala - 如何 $or 使用 reactivemongo
- visual-studio - VSTS - 拒绝用户访问另一个团队积压工作
- python - 无法在 Python Pandas 中添加具有值的多列
- watson - Data Refinery 表示我的数据限制已达到极限。有什么方法可以清除/重置?
- javascript - 当表格发生变化时,调整表格标题/行的大小以匹配表格中的第一行
- django - 如何在 Django 中打印 forms.ValidationError
- reactjs - 使用 Flexbox 垂直对齐和居中多个 div
- javascript - 我构建了一个nodejs命令行如何知道命令调用的文件夹