I have a flexbox with flex-direction: row
. The child items have a min-width
set. When the window is shrunk past the point where the min-width
is reached, the items begin to overflow the flex container.
.parent {
display: flex;
flex-direction: row;
background-color: red;
}
.child {
min-width: 100px;
flex-basis: 0px;
flex-grow: 1;
margin: 5px;
height: 100px;
background-color: blue;
}
<div class="parent">
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
</div>
https://jsfiddle.net/4t8029q8/
Is there any way to force the container to stretch to contain the items without setting an explicit min-width
on the parent? Doing so provides the behavior I am trying to achieve, but is too rigid to accomodate a variable number of items.
.parent {
display: flex;
flex-direction: row;
background-color: red;
min-width: 330px
}
.child {
min-width: 100px;
flex-basis: 0px;
flex-grow: 1;
margin: 5px;
height: 100px;
background-color: blue;
}
<div class="parent">
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
</div>
https://jsfiddle.net/4t8029q8/1/
This is what I want, for the flex-items to never overflow the flex container even if it causes the page to need a horizontal scroll.
NOTE: I have other more complicated logic requiring flex-basis: 0px
and flex-grow: 1
, so those lines cannot be removed.