在与换行符切断行前一个元素柔性模型长文本元素。但是,如果文本元素不具有长文本一切都很好。我做错了吗?
.franchisePlaceAverage {
width: 450px;
border: 4px solid #93d5ab;
}
.franchisePlaceAverage .row {
display: flex;
width: 100%;
align-items:center;
margin: 20px 0
}
.franchisePlaceAverage .star{
width: 20px;
height: 19px;
margin: 10px 28px;
background: tomato;
}
.franchisePlaceAverage .text {
}
<div class="franchisePlaceAverage">
<div class="row">
<div class="star"></div>
<div class="text">Some long text here Some long text here Some long text here Some long text here </div>
</div>
<div class="row">
<div class="star"></div>
<div class="text">Some short text here </div>
</div>
</div>
Flexbox,就试图以适应所有内容,因此与第一项(.star
)的减少。可以通过使用flex-shrink:0;
或通过迫使元件上的最小宽度防止这一点。
.franchisePlaceAverage {
width: 450px;
border: 4px solid #93d5ab;
}
.franchisePlaceAverage .row {
display: flex;
width: 100%;
align-items:center;
margin: 20px 0
}
.franchisePlaceAverage .star{
width: 20px;
flex-shrink:0;/* don't shrink me */
/* min-width: 20px; would also work */
height: 19px;
margin: 10px 28px;
background: tomato;
}
.franchisePlaceAverage .text {
}
<div class="franchisePlaceAverage">
<div class="row">
<div class="star"></div>
<div class="text">Some long text here Some long text here Some long text here Some long text here </div>
</div>
<div class="row">
<div class="star"></div>
<div class="text">Some short text here </div>
</div>
</div>