This issue occurs on both Edge and Firefox due to the default min-height
of a flex column item being set to auto
, preventing it from being smaller than its content.
To fix this, simply add min-height: 0
to the <div class="fill flex h">
element.
Check out the code snippet below:
html, body {
height: 100%;
margin: 0;
}
.flex {
display: flex;
}
.flex.v {
flex-direction: column;
}
.flex.h {
flex-direction: row;
}
.flex > * {
flex: 0 0 auto;
}
.flex > .fill {
flex: 1 1 auto;
}
.flex.auto {
overflow: auto;
}
.flex.minheight {
min-height: 0; /* added */
}
<div class="flex v" style="height: 100%;">
<div>head</div>
<div class="fill flex h minheight">
<div style="background-color: green;">side</div>
<div class="fill flex v auto" style="background-color: red;">
<div style="height: 1000px;">long content</div>
</div>
</div>
<div>foot</div>
</div>
If you also need this to work on IE, you can include the following CSS rule specifically for IE:
_:-ms-fullscreen, :root .flex.fill_ie {
flex: 1 1 0%;
}
Here's an updated version of the code snippet with the IE-specific rule included:
html, body {
height: 100%;
margin: 0;
}
.flex {
display: flex;
}
.flex.v {
flex-direction: column;
}
.flex.h {
flex-direction: row;
}
.flex > * {
flex: 0 0 auto;
}
.flex > .fill {
flex: 1 1 auto;
}
.flex.auto {
overflow: auto;
}
.flex.minheight {
min-height: 0; /* added */
}
_:-ms-fullscreen, :root .flex.fill_ie {
flex: 1 1 0%; /* added */
}
<div class="flex v" style="height: 100%;">
<div>head</div>
<div class="fill flex h minheight">
<div style="background-color: green;">side</div>
<div class="fill flex v auto" style="background-color: red;">
<div style="height: 1000px;">long content</div>
</div>
</div>
<div>foot</div>
</div>