Skip to content

Instantly share code, notes, and snippets.

@DeviaVir
Forked from LeaVerou/dabblet.css
Created April 18, 2012 12:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save DeviaVir/2413149 to your computer and use it in GitHub Desktop.
Save DeviaVir/2413149 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;
/* Flexbox hawtness */
display: box; display: flexbox;
box-align: center; flex-align: center;
box-pack: center; flex-pack: center;
}
div {
padding: 1em 1.5em;
/* Fallback to look decent w/out Flexbox */
max-width: 100em;
max-height: 100em;
margin: 1em auto;
/* Make it pretty */
}
<div>OMG, I’m centered!</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