如何对齐两个内联div以使其相邻边缘居中?
所以我希望它看起来像这样:
div1div1 div2div2
div1 div2
div1div1div1 div2div2
我尝试使用如下所示的内联块,但它只是将每一行居中。
.container {
text-align: center;
}
.left-div {
display: inline-block;
}
.right-div {
display: inline-block;
}
<div class="container">
<div class="left-div">div1div1</div>
<div class="right-div">div2div2</div>
</div>
<div class="container">
<div class="left-div">div1</div>
<div class="right-div">div2</div>
</div>
<div class="container">
<div class="left-div">div1div1div1</div>
<div class="right-div">div2div2</div>
</div>
答案 0 :(得分:1)
https://jsfiddle.net/fkfmh7md/更改div之间的距离,在填充中更改5px:0 5px到任何其他值
.container {
display: table;
table-layout: fixed;
width: 100%;
}
.container div {
display: table-cell;
padding: 0 5px;
}
.container div.left {
text-align: right;
}
&#13;
<div class="container">
<div class="left">div1div1</div>
<div>div2div2</div>
</div>
<div class="container">
<div class="left">div1</div>
<div>div2</div>
</div>
<div class="container">
<div class="left">div1div1div1</div>
<div>div2div2</div>
</div>
&#13;