I'm trying to create a container with a static header and a body that expands based on its contents up to a maximum height. After the maximum height is reached, the body should scroll. I've written code that works great in Chrome/Firefox, but in IE, the container doesn't expand correctly.
div{
border: 1px solid #DDD;
}
.container{
max-height: 150px;
display: flex;
flex-direction: column;
}
.header{
height: 40px;
}
.scroll{
flex: 1;
overflow: auto;
}
<div class="container">
<div class="header">
header
</div>
<div class="scroll">
<div>scroll</div>
<div>scroll</div>
<div>scroll</div>
<div>scroll</div>
<div>scroll</div>
<div>scroll</div>
<div>scroll</div>
<div>scroll</div>
<div>scroll</div>
<div>scroll</div>
<div>scroll</div>
</div>
</div>
If I use flex-direction: row;
instead, the height expands appropriately, but obviously my header doesn't look right then.
Is there a workaround to get a growing container with a header and scrolling body to work with IE11 and Edge? I'm not opposed to abandoning flexbox if necessary.
Status in browsers The two browsers you should still keep in mind for cross-browser compatibility are: Internet Explorer 10, which implemented the display: flexbox version of the specification with the -ms- prefix. UC Browser, which still supports the 2009 display: box version only with the -webkit- prefix.
Flexbox is (aside from optional wrapping) a single-direction layout concept. Think of flex items as primarily laying out either in horizontal rows or vertical columns.
As already told, flexbox layout is direction-agnostic, so the content elements or flex-item can be vertically or horizontally arranged based upon the requirement. The axis along with the flex-items are placed is called main-axis and the axis perpendicular to main-axis is called cross-axis.
The flex container As with all properties in CSS, some initial values are defined, so when creating a flex container all of the contained flex items will behave in the following way. Items display in a row (the flex-direction property's default is row ). The items start from the start edge of the main axis.
It appears this code works as intended in Chrome, Firefox and Edge. The problem appears to be IE11.
Here's one solution that appears to work on all four browsers:
body
element a flex container.width: 100%
).html {
height: 100%;
}
body {
display: flex;
height: 100%;
margin: 0;
}
.container {
max-height: 150px;
display: flex;
flex-direction: column;
width: 100%; /* adjustment */
}
.header {
height: 40px;
}
.scroll {
flex: 1;
overflow: auto;
}
div {
border: 1px solid #DDD;
}
<div class="container">
<div class="header">
header
</div>
<div class="scroll">
<div>scroll</div>
<div>scroll</div>
<div>scroll</div>
<div>scroll</div>
<div>scroll</div>
<div>scroll</div>
<div>scroll</div>
<div>scroll</div>
<div>scroll</div>
<div>scroll</div>
<div>scroll</div>
</div>
</div>
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