I want to contain a flex item within the parent so that it does not spill outside of the parent. Only the flex item should have a scrollbar (if necessary).
My styling works fine within Chrome and IE11, but not Firefox. I suspect there is a difference in interpretation of the flex-basis
style set on #wrapper
, but I cannot figure out why Firefox renders this differently.
Here's the desired rendering as seen in Chrome:
And here's what happens in Firefox:
I could apply a "duct tape" fix by adding #left { height: calc(100vh - 50px); }
, but I'd prefer to identify the actual inconsistency if possible.
body, html, h1 {
padding: 0;
margin: 0;
}
header {
background-color: rgba(0, 255, 255, 0.2);
height: 50px;
}
#main {
height: 100vh;
background-color: rgba(0, 255, 255, 0.1);
display: flex;
flex-flow: column;
}
#wrapper {
display: flex;
flex-grow: 2;
flex-basis: 0%;
}
#left {
overflow-y: scroll;
background-color: rgba(0, 255, 255, 0.2);
width: 30%;
}
.box {
margin: 5px 0;
height: 50px;
width: 100%;
background-color: rgba(0, 0, 0, 0.2);
}
<div id="main">
<header>
<h1>Header</h1>
</header>
<div id="wrapper">
<div id="left">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
</div>
</div>
This has to do with the flexbox specification's implied minimum sizing algorithm.
This is a Firefox bug.
Adding min-width: 0; min-height: 0
to #wrapper
seems to do the trick:
#wrapper {
display: flex;
flex-grow: 2;
flex-basis: 0%;
min-height: 0; /* NEW */
min-width: 0; /* NEW */
}
DEMO
Original Answer Below
Currently you have overflow-y: scroll
applied to #left
.
If you also apply overflow-y: scroll
to #wrapper
, the vertical scroll launches in Firefox.
As to why Firefox interprets the code differently than Chrome I can't say. The rendering engines have their differences. I recently addressed another flexbox interpretation issue between IE11 and Chrome:
More information:
Bug 1043520 - (minsizeauto-fallout) Tracking bug for web content breaking due to new "min-width:auto" / "min-height:auto" behavior on flex items
Bug 570036 - Flexible box does not allow overflow scrolling of children elements without extra markup
DEMO: http://jsfiddle.net/seqgz8qv/ (scroll works in FF)
Scroll not working with CSS3 flex box in Firefox
Flexbox and vertical scroll in a full-height app using NEWER flexbox api
Scrolling a flexbox with overflowing content
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