I'm trying to create a 2 column layout with flexbox. One is fixed width on the side and the other one (main column) fills the remaining space.
It was working until I put some contents wider than the screen with a overflow-x: scroll
parent. Now this wide content is not limited by its scroller parent.
Here is the sample:
.container {
display: flex;
}
.container .col-main {
background: gold;
flex: 1 1 100%;
}
.container .col-side {
background: cornflowerblue;
flex: 0 0 15em;
}
.slider-container {
overflow-x: scroll;
}
.slider-container .slider {
background: repeating-linear-gradient(45deg, darkseagreen, darkseagreen 10px, dimgray 10px, dimgray 20px);
width: 150em;
height: 10em;
}
<div class="container">
<div class="col-main">
<div class=slider-container>
<div class="slider">
Foo
</div>
</div>
</div>
<div class="col-side">
Side
</div>
</div>
It should be rendered like this:
One of the most common causes of overflow is fixed-width elements. Generally speaking, don't fix the width of any element that should work at multiple viewport sizes.
If you are using flexbox and want the content to wrap, you must specify flex-wrap: wrap . By default flex items don't wrap. To have the images be three-across, you should specify flex-basis: 33.33333% .
Try adding min-width: 0;
to the flex item.
.container .col-main {
...
min-width: 0;
}
jsFiddle
4.5. Implied Minimum Size of Flex Items
To provide a more reasonable default minimum size for flex items, this specification introduces a new
auto
value as the initial value of themin-width
andmin-height
properties defined in CSS 2.1. [CSS21]
You can add width: 0
to the container.
.container {
display: flex;
}
.container .col-main {
background: gold;
flex: 1 1 100%;
width: 0;
}
.container .col-side {
background: cornflowerblue;
flex: 0 0 15em;
}
.slider-container {
overflow-x: scroll;
}
.slider-container .slider {
background: repeating-linear-gradient(45deg, darkseagreen, darkseagreen 10px, dimgray 10px, dimgray 20px);
width: 150em;
height: 10em;
}
<div class="container">
<div class="col-main">
<div class=slider-container>
<div class="slider">
Foo
</div>
</div>
</div>
<div class="col-side">
Side
</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