我试图将两个盒子彼此叠放在另一个div的底部。我有以下代码:
<div style = "height:400px;width:400px;border:1px solid #000;">
<div style = "position:relative;height:100px;width:100px;border:1px solid #000;bottom:0px;">
</div>
<div style = "position:relative;height:100px;width:100px;border:1px solid #000;bottom:0px;">
</div>
</div>
问题在于盒子位于容器顶部而不是底部。请帮助。
最佳答案
您必须使容器相对,并且框绝对:
<div style = "height:400px;width:400px;border:1px solid #000; position:relative;">
<div style = "position:absolute;height:100px;width:100px;border:1px solid #000;bottom:0px;">
</div>
<div style = "position:absolute;height:100px;width:100px;border:1px solid #000;bottom:0px;">
</div>
编辑权威性答案:
<div style = "height:400px;width:400px;border:1px solid #000; position: relative;">
<div style = "position: absolute;height:100px;border:1px solid #000; bottom: 0;">
<div style = "height:100px;width:100px;border:1px solid #000;float:left;"></div>
<div style = "height:100px;width:100px;border:1px solid #000;float:left;">
</div>
</div>
关于html - CSS:定位不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18958101/