[英]Apply flex to all siblings if one siblings needs to flex
Example problem:示例问题:
When there is no enough space, one row starts to flex but others won't if they still have enough space, can I make it so every row flex if at least one has to?当没有足够的空间时,一行开始弯曲,但如果他们仍有足够的空间,其他行不会弯曲,如果至少有一个必须这样做,我可以让每一行都弯曲吗?
So instead of this I want this所以我想要这个而不是这个
Assets:资产:
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 510 510"><title>x</title><line x1="5" y1="5" x2="505" y2="505" style="fill:none;stroke:#000;stroke-miterlimit:10;stroke-width:10px"/><line x1="5" y1="505" x2="505" y2="5" style="fill:none;stroke:#000;stroke-miterlimit:10;stroke-width:10px"/><rect x="5" y="5" width="500" height="500" style="fill:none;stroke:#000;stroke-miterlimit:10;stroke-width:10px"/></svg>
html: html:
<div className='container'>
<div className='container__side top'>
<div className='container__row nameone'>
<img className='container__type' src='...'/>
<svg className='container__item' ... />
// each row have different amount of svg items, because it loop throw array fecthed from api
</div>
<div className='container__row nametow'>
</div>
// etc
</div>
<div className='container__side bottom'>
</div>
</div>
scss: scss:
.container {
background: white;
display: flex;
flex-direction: column;
padding: 1rem;
&__row {
display: flex;
}
&__type {
margin-right: 2rem;
width: 5rem;
height: 5rem;
object-fit: contain;
}
&__item {
padding: .5rem;
width: 7rem;
height: 7rem;
}
}
You can just add flex-shrink: 0;
您可以添加
flex-shrink: 0;
to &__item
.到
&__item
。
You final CSS should look like this:您最终的 CSS 应该如下所示:
&__item {
padding: .5rem;
width: 7rem;
height: 7rem;
flex-shrink: 0;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.