我有一个父容器,里面有一些子组件。最后一个孩子必须放在容器的底部。我尝试使用justify-content: space-between
,但它不适用于我,因为我需要最后一个元素和其他元素之间的空间更大,更明显。我结束了尝试position:absolute
,bottom: 0
,但孩子的宽度大于父母。为什么我的位置:绝对孩子溢出父母的边界?
也许有更好的方法来做到这一点,通过与flex混合,只是无法做到这一点。
.Parent {
background: #F8F8F8;
height: 400px;
padding: 20px;
width: 395px;
position: relative;
max-width: 395px;
border: solid 1px red;
}
.First--Child {
border: solid 1px blue;
height: 40px;
margin: 10px 0;
}
.Second--Child {
border: solid 1px green;
height: 40px;
margin: 10px 0;
}
.Third--Child {
border: solid 1px violet;
height: 40px;
margin: 10px 0;
}
.Last--Child {
border: solid 1px cyan;
height: 60px;
position: absolute;
bottom: 0;
width: 100%;
margin: 0 0 10px 0;
display: flex;
justify-content: space-between;
}
.Left--Button,
.Right--Button {
border: solid 1px gray;
width: calc(100% - 300px);
}
<div class='Parent'>
<div class='First--Child'>
</div>
<div class='Second--Child'>
</div>
<div class='Third--Child'>
</div>
<div class='Last--Child'>
<button class='Left--Button'>Left</button>
<button class='Right--Button'>Right</button>
</div>
</div>
不错!为什么孩子的宽度超过父母的宽度? –
@AndresZapata它不是 – TylerH
它打破了它,因为它与paren宽度相同,不考虑填充,但布局尊重填充。 –