Skip to content

Instantly share code, notes, and snippets.

@kosmikko
Created April 26, 2012 05:52
Show Gist options
  • Select an option

  • Save kosmikko/2496348 to your computer and use it in GitHub Desktop.

Select an option

Save kosmikko/2496348 to your computer and use it in GitHub Desktop.
Vertical centering with Flexbox + margin fallback
/**
* Vertical centering with Flexbox + margin fallback
* Lea Verou & David Storey
*/
html, body { height: 100%; }
body {
width: 100%; /* needed for FF */
margin: 0;
}
#wrapper {
/* Make it pretty */
background: slategray;
text-align: center;
border-radius: .3em;
color: #405060;
font: bold 150% sans-serif;
text-shadow: 0 2px 1px hsla(0,0%,100%,.2);
}
#sidebar {
/* Flexbox hawtness */
display: box;
display: flexbox;
padding: 1em 1.5em;
background: #bbb;
width: 30%;
}
#main {
padding: 1em 1.5em;
display: box; display: flexbox;
width: 70%;
}
<div id="wrapper">
<div id="main">Main content</div>
<div id="sidebar">Sidebar</div>
</div>
{"view":"split-vertical","fontsize":"100","seethrough":"","prefixfree":"1","page":"css"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment