I'm wondering whether I actually understand flex-shrink
an flex-grow
properly. I'm trying to understand why the flex children aren't the same size. I just want to be able to add as many flex children (i.e. .flex-item
divs) into the containing parent div as possible, and for them to resize to the same widths as each other. In this case the text is pushing the width way out for one of them.
How can this be fixed without adding a hard-coded flex-basis
?
Any explanation would be very helpful. Thanks for any help here.
#container {
display: flex;
justify-content: space-between;
width: 100%;
background: pink;
overflow: hidden; /* words should wrap anyway... */
}
.flex-item {
border: 1px solid red;
flex: 0 0 auto; /* should make flex items equal size */
word-wrap: break-all;
/* flex-basis: 0; makes flex items too narrow; they should stretch to fill width equally depending on no of flex items inside containing div. Also shouldn't require hard-coding the width */
}
<div id='container'>
<div class='flex-item'>
<p>ri bergber gyiruek weeuyrg eir7 gueruygergb e8iygerg ier7 guer y org ery8g e g8e ergerg</p>
</div>
<div class='flex-item'>
<p>ri bergber gyiruew</p>
</div>
<div class='flex-item'>
<p>ri bergber gyiruek wveeuyrg eir7 gueruygergb e8iygerg ier7 guer y org ery8g e g8e ergervwev we wefwew fwef we fwf wek wveeuyrg eir7 gueruygergb e8iygerg ier7 guer y org ery8g e g8e ergervwev we wefwew fwef we fwf wrgber gyiruek wveeuyrg eir7 gueruygergb e8iygerg ier7 guer y org ery8g e g8e ergervwev we wefwew fwef we fwf wek wveeuyrg eir7 gueruygergb e8iygerg ier7 guer y org ery8g e g8e ergervwev we wefwew fwef we fwf wg</p>
</div>
</div>
Codepen: https://codepen.io/anon/pen/JgRawo