Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flexbox body and main min-height

https://jsfiddle.net/vz7cLmxy/

I'm trying to have the body to expand but the min-height does not work. I've read other related topics but can't get my head around it.

CSS and html

body,
html {
  padding: 0;
  margin: 0;
  min-height: 100%;
}

body {
  display: flex;
  background: #eee;
  flex-direction: column;
}

.menu {
  background: red;
  color: #fff;
  padding: 10px;
}

.wrap {
  display: flex;
}

.sidebar {
  background: #ddd;
  width: 300px;
}

.main {
  background: #ccc;
  flex: 1;
}

.footer {
  background: #000;
  color: #fff;
  padding: 10px;
}
<div class="menu">Menu</div>

<div class="wrap">
  <div class="sidebar">Sidebar</div>
  <div class="main">Main</div>
</div>

<div class="footer">Footer</div>

Expected result is that main is streched to fill the height if it's less than 100%.

like image 686
Jens Törnell Avatar asked May 25 '16 08:05

Jens Törnell


1 Answers

Use flex: 1 on the centered element:

.Site {
  display: flex;
  min-height: 100vh;
  flex-direction: column;
}

.Site-content {
  flex: 1;
  background-color:#bbb;
}
<body class="Site">
  <header>This is the header text ☺</header>
  <main class="Site-content">…</main>
  <footer>This is the footer text ☻</footer>
</body>
like image 100
Randy Avatar answered Sep 22 '22 16:09

Randy