Levi Murray
Levi Murray

Reputation: 187

How to use flexbox to fill remaining height?

html,
body {
  height: 100%;
}
.site-main {
  height: calc(100% - 72px);
  display: flex;
}
.site-main > div {
  min-width: 85%;
  height: 100%;
}
.site-main > aside {
  min-width: 15%;
  height: 100%;
  background-color: $darkest-blue-grey;
}
<header>
  <h1>Title</h1>
</header>
<div class="site-main">
  <div></div>
  <aside></aside>
</div>

I have the header at a fixed height of 72px.

I have given .site-main div a width of 85%.

I have given .site-main aside a width of 15%.

What I want is for .site-main div and .site-main aside to be side by side, and have .site-main fill the remaining white space after the header.

And have .site-main div and .site-main aside fill .site-main's height.

Any help would be greatly appreciated!

Upvotes: 3

Views: 5772

Answers (2)

Asons
Asons

Reputation: 87191

For you who need to support IE11 (and 10), this one solves the IE min-height bug

Note, for this to work on IE10, prefixed flexbox properties needs to be added

html, body {
  margin: 0;
}
body {
  display: -ms-flexbox;        /* IE 10 */
  display: flex;               /* IE11/10 bug fix    */
}
.wrapper {
  -ms-flex: 1;                 /* IE 10 */
  flex: 1;                     /*  fill 100% width   */
  display: -ms-flexbox;        /* IE 10 */
  display: flex;
  -ms-flex-direction: column;  /* IE 10 */
  flex-direction: column;
  min-height: 100vh;
}
header {
  height: 72px;
}
.site-main {
  -ms-flex: 1;                 /* IE 10 */
  flex: 1;                     /*  fill 100% height  */
  display: -ms-flexbox;        /* IE 10 */
  display: flex;
}
.site-main > div {
  width: 85%;
  background-color: lightgreen;
}
.site-main > aside {
  width: 15%;
  background-color: lightblue;
}
<div class="wrapper">
  <header>
    <h1>Title</h1>
  </header>
  <div class="site-main">
    <div></div>
    <aside></aside>
  </div>
</div>

Upvotes: 1

Nenad Vracar
Nenad Vracar

Reputation: 122047

You can use flex-direction: column on body and flex: 1 on site-main.

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  margin: 0;
  padding: 0;
}
header {
  height: 75px;
}
.site-main {
  display: flex;
  flex: 1;
}
.site-main div {
  flex: 0 0 85%;
  background: lightblue;
}
aside {
  flex: 0 0 15%;
  background: lightgreen;
}
<header>
  <h1>Title</h1>
</header>
<div class="site-main">
  <div></div>
  <aside></aside>
</div>

Upvotes: 7

Related Questions