In Google Chrome, how do I force an element nested inside of a member of a flexbox (by "member of a flexbox" I mean a child of an element styled with display:flex
) to limit its size to the size of the flexbox member it's nested under? For example, suppose I have the following:
<div style="display:flex; flex-direction:column; height:100vh;">
<div style="height:60px;">Static header</div>
<div style="flex: 1 1 0; overflow:hidden;">
<div style="overflow:auto; height:100%;" id="problem-is-here">
Lots and lots of content, way too much to fit in the viewport
</div>
</div>
</div>
Because the first child div
of the outermost div
has a constant height, it ends up exactly 60px tall, and because the second child div
has a flex-grow
of 1, it gets the rest of the space available (in this case, 100% of the viewport minus 60px). I can confirm that this element's dimensions according to Inspect Element are just large enough to take up the rest of the viewport space.
In Firefox and IE11, due to the height:100%
, the innermost element (id="problem-is-here"
) takes on the height computed for its parent. Therefore, since it is too small to display its content and overflow
is set to auto
, it (and not the entire body
) gets a vertical scrollbar. This is what I want.
In Chrome, however, the innermost element is rendered with enough height to contain all of its content, which is a larger height than its parent. Thus, because its parent has overflow:hidden
, no scrollbar appears and the excess content is inaccessible. How do I tell Chrome to render this innermost element with height at most equal to that of its parent, when the parent height is determined by a flexbox, not a CSS height
property? Note that I can't give either the innermost div
or its parent a definite height
value since in the application I'm working on, the number of other flexbox members can vary.
Note: I have tried a few suggestions from other answers, such as setting all elements to have min-height:0
instead of auto
, or ensuring flex-basis
is set to 0
, but none of these have worked. See
http://plnkr.co/edit/UBRcrNmR5iDbn3EXu6FI?p=preview
for an example that illustrates the problem. (The div
with id heres-the-problem
is the one whose height I want limited to the height of its parent.)