我正在嘗試使用min-width
屬性使動態寬度div.widget__stars
動態化。但是,當我使用display: table-cell;
時,min-width
屬性會被忽略。使用表格單元的動態寬度
我已經試過display: inline-block;
但它沒有工作。
紅色條(div.widget__bar
)也不能有固定的寬度。
這是我的例子:
<div class="container">
<div class="widget-row">
<div class="widget widget__stars">5 stars</div>
<div class="widget widget__bar"></div>
<div class="widget widget__percent">70%</div>
</div>
</div>
CSS:
.container,
.widget-row {
width: 100%;
}
.widget-row {
display: table;
}
.widget {
display: table-cell;
vertical-align: middle;
}
.widget__bar {
background: tomato;
}
.widget__stars {
width: 48px;
padding-right: 5px;
font-weight: bold;
}
.widget__percent {
width: 50px;
padding-left: 5px;
}
如果您的.widget__stars
設置寬度爲min-width: 48px;
紅色欄消失。
有關如何解決此問題的任何想法?
謝謝Paulie_D。我正在尋找類似的CSS技巧,但無法找到它。我嘗試使用白色空間:nowrap;但它與其他內容混淆了。所以你的解決方案工作=) – brunodd