Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

3 rows, 100% height layout, with flexbox

Tags:

html

css

flexbox

I'd like to know: is it possible to build a 3 rows layout, 100% height, with flexbox?

<header> The header content goes here. </header>
<div class="content"> The main content goes here. </div>
<footer> The footer content goes here. </footer>

fixed-height header and footer, while content the liquid part.

I mean, something like this but without absolute positioning:

* {
  margin: 0;
}
header {
  position: absolute;
  width: 100%;
  height: 64px;
  top: 0;
  background: red;
}
footer {
  position: absolute;
  width: 100%;
  height: 64px;
  bottom: 0;
  background: green;
}
.content {
  position: absolute;
  width: 100%;
  top: 64px;
  bottom: 64px;
  background: blue;
}
<header>The header content goes here.</header>

<div class="content">The main content goes here.</div>

<footer>The footer content goes here.</footer>

http://jsfiddle.net/BMxzn/

like image 262
Luca Reghellin Avatar asked Jan 16 '17 15:01

Luca Reghellin


1 Answers

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
}
.content {
  flex: 1;     /* this is the key; consumes all available height */
  background: blue;
}
header {
  height: 64px;
  background: red;
}
footer {
  height: 64px;
  background: green;
}
* {
  margin: 0;
}
<header>The header content goes here.</header>
<div class="content">The main content goes here.</div>
<footer>The footer content goes here.</footer>
like image 192
Michael Benjamin Avatar answered Oct 25 '22 13:10

Michael Benjamin