Reputation: 63567
How can I make a div fill up the remaining vertical space using display: flex
?
In my example below, the main
element should fill up all space not used by the nav. If this worked correctly, we wouldn't see any red.
HTML:
<nav></nav>
<main></main>
CSS:
body {
height: 100%;
display: flex;
flex-direction: column;
background: red;
margin: 0;
}
nav {
height: 40px;
background: orange;
}
main {
display: flex;
flex: 1;
background: purple;
}
Upvotes: 2
Views: 637
Reputation: 39006
Try adding html
next to your body
selector.
html, body {
height: 100%;
display: flex;
flex-direction: column;
background: red;
margin: 0;
}
However, I would suggest to put the flex stuff inside a container.
html, body, .container {
height: 100%;
margin: 0;
}
.container {
display: flex;
flex-direction: column;
background: red;
}
nav {
height: 40px;
background: orange;
}
main {
display: flex;
flex: 1;
background: purple;
}
<div class="container">
<nav></nav>
<main></main>
</div>
Upvotes: 5