dzm
dzm

Reputation: 23554

Flexgrid holy grail with 100% height

I have a twist on the "holy grail" layout and you'll notice that the #main has a min-height: 800px. What I'm really looking for is 100% height, then as I add content within the section the rest of the layout continues down with it (as it currently does).

Any idea how to achieve this, with 100% height and not explicitly setting 800px?

body {
  font: 24px Helvetica;
  background: #999999;
  margin: 0;
  padding: 0;
  height: 100%;
}

#main {
  min-height: 800px;
  margin: 0;
  padding: 0;
  display: flex;
  flex-flow: row;
}

#main>article {
  border: 1px solid #cccc33;
  background: #dddd88;
  flex: 3 1 60%;
  order: 3;
}

#main>nav {
  border: 1px solid #8888bb;
  background: #ccccff;
  flex: 1 6 70px;
  order: 1;
  max-width: 70px;
  min-width: 70px;
}

#main>aside {
  border: 1px solid #8888bb;
  background: #ccccff;
  flex: 1 6 300px;
  order: 2;
  max-width: 300px;
  min-width: 300px;
}

header {
  display: block;
  padding: 5px;
  min-height: 70px;
  border: 1px solid #eebb55;
  background: #ffeebb;
}

section {
  margin: 10px;
}

.container {
  margin: 0;
  padding: 0;
  display: flex;
  flex-flow: row;
}

.container>.field {
  width: 100%;
  background: #dddd88;
  order: 2;
}

.container>.left {
  width: 4px;
  background: black;
  order: 1;
}

.container>.right {
  width: 4px;
  background: black;
  order: 3;
  display: flex;
}

.top,
.bottom {
  display: block;
  height: 4px;
  background: red;
}
<div id='main'>
  <article>
    <header>header</header>
    <section>
      <div class="top"></div>
      <div class="container">
        <div class="field">
          Sub Container w/ borders
        </div>
        <div class="left"></div>
        <div class="right"></div>
      </div>
      <div class="bottom"></div>
    </section>
  </article>
  <nav>nav</nav>
  <aside>aside</aside>
</div>

Upvotes: 3

Views: 384

Answers (1)

Michael Benjamin
Michael Benjamin

Reputation: 371699

If you want an element to occupy 100% viewport height, with the option to expand to accommodate additional content, use min-height: 100vh (demo).

For reasons explained in the following posts, percentage heights are not as efficient and easy to use as viewport percentage heights.

Upvotes: 4

Related Questions