I'm currently experimenting with flexbox layouts and have a problem, that overflow
wont get applied, when I nest multiple flexboxes.
As long as I just use one level of flex boxes (see example 1), everything works fine: As soon as its content exceed the given space, scrollbars are applied to the red box (#top
).
If I, however, introduce another layer of flexboxes (see example two), there is no scrollbar on the blue box (#right
). Instead the scrollbars appear on the body element completely ignoring the overflow: auto
setting on the blue box.
So my question is: How can I get overflow
to work when using nested flexboxes?
Remark: I tested this with Chrome45, Firefox 40 and IE11. The behavior is consistent across all.
Below is the code as well as a fiddle link for both cases.
(1) Just one flexbox, no nesting
<div id="container">
<div id="top">
...
</div>
<div id="bottom">
blub
</div>
</div>
html, body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
#container{
background-color: yellow;
flex-direction: column;
display: flex;
height: 100%;
}
#top {
background-color: red;
flex-grow: 1;
display: flex;
flex-direction: row;
overflow: auto;
white-space:pre;
}
#bottom {
background-color: green;
height: 4em;
}
(2) nested flexboxes
<div id="container">
<div id="top">
<div id="left">
</div>
<div id="right">
...
</div>
</div>
<div id="bottom">
blub
</div>
</div>
html, body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
#container{
background-color: yellow;
flex-direction: column;
display: flex;
height: 100%;
}
#top {
background-color: red;
flex-grow: 1;
display: flex;
flex-direction: row;
}
#right {
white-space: pre;
overflow: auto;
background-color: blue;
width: 5em;
}
#left {
flex-grow: 1;
background-color: orange;
}
#bottom {
background-color: green;
height: 4em;
}