How do I make a flex parent with a nowrap
flex-wrap expand to fit its content even if that means overflowing whatever is wrapping the parent?
Basically, the content has a min-width, I want the flex parent not to shrink more than the space all the flex items need.
Here is a JSFiddle https://jsfiddle.net/lazamar/odat477r/
.wrapper {
background-color: yellowgreen;
display: block;
padding: 10px;
max-width: 180px;
}
.parent {
display: flex;
flex-flow: row nowrap;
background-color: yellow;
}
.child {
display: block;
background-color: orange;
margin: 10px;
min-width: 50px;
}
<div class="wrapper">
<div class="parent">
<div class="child">Content</div>
<div class="child">Content</div>
<div class="child">Content</div>
<div class="child">Content</div>
<div class="child">Content</div>
</div>
</div>
The initial value of the flex-wrap property is nowrap . This means that if you have a set of flex items that are too wide for their container, they will overflow it.
The flex-grow property specifies how much the item will grow relative to the rest of the flexible items inside the same container. Note: If the element is not a flexible item, the flex-grow property has no effect.
The answer is what t1m0n said. Use display: inline-flex
instead of display: flex
for the parent.
.wrapper {
background-color: yellowgreen;
display: block;
padding: 10px;
max-width: 180px;
}
.parent {
display: inline-flex; /* -- only change --*/
flex-flow: row nowrap;
background-color: yellow;
}
.child {
display: block;
background-color: orange;
margin: 10px;
min-width: 50px;
}
<div class="wrapper">
<div class="parent">
<div class="child">Content</div>
<div class="child">Content</div>
<div class="child">Content</div>
<div class="child">Content</div>
<div class="child">Content</div>
</div>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With