2 回答

TA貢獻1909條經驗 獲得超7個贊
您可以考慮flex-grow:1;flex-basis:0%使用left和right元素,然后text-align在其中對齊內容。我添加了一個額外的包裝程序,以僅在文本周圍保留背景。
訣竅是通過僅刪除中間內容并將其均分為左元素和右元素來計算可用空間。
.container {
margin: 20px 0;
padding-top:10px;
background:linear-gradient(#000,#000) center/5px 100% no-repeat; /*the center*/
}
.row {
background-color: lime;
display: flex;
color: #fff;
}
.item:not(:nth-child(2)) {
flex-basis: 0%;
flex-grow: 1;
}
.item:last-child {
text-align: right;
}
.item span{
background-color: blue;
display:inline-block;
padding: 16px;
height:100%;
box-sizing:border-box;
}
<div class="container">
<div class="row">
<div class="item"><span>left, slightly longer</span></div>
<div class="item"><span>center, this item is much longer</span></div>
<div class="item"><span>right</span></div>
</div>
</div>
您也可以通過使元素保持關閉來執行相同的操作。只需調整文本對齊即可:
.container {
margin: 20px 0;
padding-top:10px;
background:linear-gradient(#000,#000) center/5px 100% no-repeat; /*the center*/
}
.row {
background-color: lime;
display: flex;
color: #fff;
}
.item:not(:nth-child(2)) {
flex-basis: 0%;
flex-grow: 1;
}
.item:first-child {
text-align: right;
}
.item span{
background-color: blue;
display:inline-block;
padding: 16px;
height:100%;
box-sizing:border-box;
}
<div class="container">
<div class="row">
<div class="item"><span>left, slightly longer</span></div>
<div class="item"><span>center, this item is much longer</span></div>
<div class="item"><span>right</span></div>
</div>
</div>

TA貢獻1796條經驗 獲得超4個贊
您能否給flex-grow:1作為商品類別并檢查
.item {
background-color: blue;
color: #fff;
padding: 16px;
flex-grow:1;
}
希望這是您要尋找的
- 2 回答
- 0 關注
- 592 瀏覽
相關問題推薦
添加回答
舉報