我有一个使用弹性框垂直居中的div。但现在有没有办法让它与右边相符?
答案 0 :(得分:15)
一种选择是将justify-content: flex-end
添加到flexbox容器中:(example)
.parent {
display: flex;
width: 200px;
height: 200px;
border: 1px solid;
align-items: center;
justify-content: flex-end;
}
.parent > .child {
width: 50%;
height: 50%;
border: 2px solid #f00;
}

<div class="parent">
<div class="child"></div>
</div>
&#13;
或者,您也可以将margin-left: auto
添加到flexbox项目:(example)
.parent {
display: flex;
width: 200px;
height: 200px;
border: 1px solid;
align-items: center;
}
.parent > .child {
width: 50%;
height: 50%;
border: 2px solid #f00;
margin-left: auto;
}
&#13;
<div class="parent">
<div class="child"></div>
</div>
&#13;