我想在左边设置order id
并将其余两个设置在div的最右边。 total
和view
元素之间应该有相等的空格,但应该在右边。 justify-content:space-between
在它们之间设置相等的空间,flex-grow或shrink在我的情况下不起作用。难道我做错了什么?请帮忙。
<div layout="row" layout-align="space-between" class="orders-table-header">
<p class="orders-table-text text-center" style="flex-shrink:2">ORDER ID</p>
<p class="orders-table-text text-center" style="flex-grow:1">TOTAL</p>
<p class="orders-table-text text-center" style="flex-grow:1">VIEW</p>
</div>
答案 0 :(得分:2)
你不能分成 66%+ 33%+ 33%,你可以给flex
2 + 1 + 1
.text-center {
text-align:center;
}
&#13;
<div layout="row" layout-align="space-between" class="orders-table-header" style="display: flex;">
<p class="orders-table-text text-center" style="flex: 2;background-color: aquamarine;">ORDER ID</p>
<p class="orders-table-text text-center" style="flex: 1;background-color: bisque;">TOTAL</p>
<p class="orders-table-text text-center" style="flex: 1;background-color: coral;">VIEW</p>
</div>
&#13;
答案 1 :(得分:1)
尝试在弹性项目上使用margin
来对齐left
和right
div {
display: flex;
}
.orders-table-text {
border: 1px solid red;
}
.orders-table-text.right {
margin-left: auto;
}
.orders-table-text.left {
margin-right: auto;
}
<div layout="row" layout-align="space-between" class="orders-table-header">
<p class="orders-table-text text-center left">ORDER ID</p>
<p class="orders-table-text text-center right">TOTAL</p>
<p class="orders-table-text text-center right">VIEW</p>
</div>
答案 2 :(得分:0)
如果您将两个正确的项目包装成div,justify-content: space-between
将按预期工作:
.orders-table-header {
display: flex;
justify-content: space-between;
}
.orders-table-text {
border: 1px solid red;
}
.right {
display: flex;
}
<div layout="row" layout-align="space-between" class="orders-table-header">
<div>
<p class="orders-table-text text-center left">ORDER ID</p>
</div>
<div class="right">
<p class="orders-table-text text-center right">TOTAL</p>
<p class="orders-table-text text-center right">VIEW</p>
</div>
</div>