I have a Flex-Box Container that contains various items. I want all items to have the same width, but I also want to avoid clipping.
My HTML Structure goes a bit like this (Compiled with Blade):
<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>
With the following CSS (Compiled with 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;
}
}
}
}
}
When viewed, it appears like this:
Of course, this isn't what I want.
I'd like these items to all share the same width, like this:
Now bare in mind that I'm not asking for a two-column solution, nor a browser-based responsive solution. The deciding factor for the width here are the items themselves, not how wide the browser is.
For example, if I remove the long names/emails from the example, it should look like this:
I've tried doing things like flex: 1 0 200px
for each item, but that ends up looking like this:
The last row of items don't share the same width, and partial clipping occurs on Lance's item.
Hopefully I've made clear of what exactly I want. I don't mind having to specify a width in the CSS, if it is only a minimum width.
Here's what I have on Code Pen. Feel free to play around with that.
I'd like to stick to a CSS solution, but I'll accept a JavaScript solution if it does what I want.