I have a nested structure of flexbox containers, where an inner container needs to show potentially large content in a scrollable pane. However, sometimes the content is small.
There's an additional container that needs to be always visible, and that I'd like to have just below the scrollable content, i.e. not far down at the bottom unless the scrollable pane content "pushes" it down - the viewport can be much larger than the content.
What I have right now does everything except have the "Right bottom" come up when the "Right top content" is small:
JsFiddle: https://jsfiddle.net/u6dou3wf/10/
.main {
display: flex;
height: 200px;
}
.left {
flex: 1 1 0;
background: red;
}
.right {
flex: 0 0 0;
display:flex;
flex-direction: column;
background: green;
padding: 4px;
}
.right-top-wrapper {
flex: 1 1 0;
overflow-x: auto;
overflow-y: scroll;
background: blue;
}
.right-top-content {
margin: 4px;
height:100px;
width:100px;
background: pink;
}
.right-bottom {
flex: 0 0 0;
background: yellow;
margin: 4px;
}
<div class="main">
<div class="left">
Left content
</div>
<div class="right">
<div class="right-top-wrapper">
<div class="right-top-content">
Right top content
</div>
</div>
<div class="right-bottom">
Right bottom
</div>
</div>
</div>
How can I get the "Right bottom" to be snugly below the "Right top content", i.e. get the blue section to shrink if the pink section is small, and then grow to whatever size is available inside the green (minus yellow) if the pink section is large?
I have tried .right-top-wrapper { flex: 0 1 0; }
but then it shrinks to nothing (a consequence of overflow-y: scroll
or auto
, which I have to have to allow large "Right top content").