我有一个包含各种项目的Flex-Box容器。我希望所有项目具有相同的宽度,但我也想避免裁剪。CSS Flexbox:使所有项目相同尺寸,无需裁剪
我的HTML结构去有点像这样(用刀片编译):
<div class="container-tease">
@foreach($users as $user)
<section class="tease tease-user">
<img class="avatar" src="{{ $user->avatar }}">
<div class="summary">
<h3 class="name">{{ $user->name }}</h3>
<span class="email">{{ $user->email }}</span>
</div>
</section>
@endforeach
</div>
用下面的CSS(编译时SASS):
.container-tease
{
font-family: 'Source Sans Pro', sans-serif;
display: flex;
flex-wrap: wrap;
align-content: flex-start;
justify-content: flex-start;
.tease
{
margin: 10px;
padding: 7px;
&.tease-user
{
display: flex;
align-items: center;
background-color: #EEE;
border: 1px solid #AAA;
border-radius: 8px;
.avatar
{
border-radius: 24px;
background-color: white;
width: 48px; height: 48px;
}
.summary
{
margin-left: 10px;
margin-right: 5px;
.name
{
margin: 0 0 5px 0;
font-size: 20px;
line-height: 20px;
white-space: nowrap;
}
.email
{
margin-left: 2px;
font-size: 14px;
line-height: 14px;
color: #888;
}
}
}
}
}
查看时,它看起来是这样的:
当然,这不是我婉吨。
我想这些项目都有着相同的宽度,这样的:
现在记住裸露,我不是要求一个两列的解决方案,也没有浏览器的基于响应的解决方这里宽度的决定因素是项目本身,而不是浏览器的宽度。
例如,如果我删除长文件名/电子邮件从例子中,它应该是这样的:
我试着做这样的事情flex: 1 0 200px
每个项目,但最终这样看:
项目的最后一行不共享相同的宽度,并在兰斯的项目出现局部裁剪。
希望我已经明确了我究竟想要什么。我不介意在CSS中指定宽度,如果它只有最小宽度,则为。
这就是我对Code Pen。随意玩这个。
我想坚持一个CSS解决方案,但如果它符合我的要求,我会接受一个JavaScript解决方案。
Flexbox,就不能这样做......你** **你需要使用Javascript。 –
@Paulie_D,谢谢澄清。我删除了我的答案。 –
@Boom,我认为你的问题可以简单地简单地说:*所有的弹性项目必须是相等的宽度。内容最长的弹性项目设置长度。* –