Last active
August 29, 2015 14:13
-
-
Save eljefedelrodeodeljefe/5d5f9aebe533d72e6d60 to your computer and use it in GitHub Desktop.
CSS vertical fill the body with flexbox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*, *:before, *:after | |
{ | |
-moz-box-sizing: border-box; | |
-webkit-box-sizing: border-box; | |
box-sizing: border-box; | |
} | |
html, body | |
{ | |
width: 100%; | |
height: 100%; | |
margin: 0; | |
padding: 0; | |
} | |
body | |
{ | |
background: #444444; | |
color: #cccccc; | |
font-size: 14px; | |
} | |
.flexbox-parent | |
{ | |
width: 100%; | |
height: 100%; | |
display: flex; | |
flex-direction: column; | |
justify-content: flex-start; /* align items in Main Axis */ | |
align-items: stretch; /* align items in Cross Axis */ | |
align-content: stretch; /* Extra space in Cross Axis */ | |
background: white; | |
} | |
.flexbox-item | |
{ | |
} | |
.flexbox-item-grow | |
{ | |
flex: 1; /* same as flex: 1 1 auto; */ | |
} | |
.flexbox-item.header | |
{ | |
background: grey; | |
} | |
.flexbox-item.footer | |
{ | |
background: lightgrey; | |
} | |
.flexbox-item.content | |
{ | |
background: grey; | |
} | |
.fill-area | |
{ | |
display: flex; | |
flex-direction: row; | |
justify-content: flex-start; /* align items in Main Axis */ | |
align-items: stretch; /* align items in Cross Axis */ | |
align-content: stretch; /* Extra space in Cross Axis */ | |
} | |
.fill-area-content | |
{ | |
background: rgba(0, 0, 0, .3); | |
border: 1px solid #000000; | |
/* Needed for when the area gets squished too far and there is content that can't be displayed */ | |
overflow: auto; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is a little hack to get 'fixed' headers and footers while maintaining a body with variable height but 100/ filled. | |
SO: It's taking from the below stackoverflow comment. | |
http://stackoverflow.com/a/15388247/3580261 | |
JSbin | |
http://jsbin.com/cifone/6/edit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<div class="flexbox-parent"> | |
<div class="flexbox-item header"> | |
Header | |
</div> | |
<div class="flexbox-item fill-area content flexbox-item-grow"> | |
<div class="fill-area-content flexbox-item-grow"> | |
Content | |
<br /><br /> | |
Emulates | |
<br /><br /> | |
This | |
</div> | |
</div> | |
<div class="flexbox-item footer"> | |
Footer | |
</div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment