我想知道如何在一个 div 中对齐三个元素。基本上,它应该是这样的
已解决。
对于 future 的读者,我的问题的解决方案如下所示
<div style="text-align: center;">
<span style="float: left;">LEFT</span>
<span style="margin: auto;">CENTER</span>
<span style="float: right;">RIGHT</span>
</div>
最佳答案
.container{
display: flex; // working with all latest browsers
display: -webkit-flex; // for old version of safari
display: -ms-flex; // for old versions of IE
justify-content: space-between;
}
.container span{
flex: 1;
text-align: center;
}
<div class="container">
<span>LEFT</span>
<span>CENTER</span>
<span>RIGHT</span>
</div>
如果您要在 container
中添加更多数据,那最好不过了。它将给出相等的间距。内联样式不是更好的选择
Demo这里
关于HTML/CSS 对齐 div 中的多个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38695522/