-
-
Save vasilisvg/2412191 to your computer and use it in GitHub Desktop.
Visually correct vertical centering with Flexbox + margin fallback
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
/** | |
* Visually correct vertical centering with Flexbox + margin fallback | |
* Lea Verou & David Storey | |
* Slight adjustment by Vasilis van Gemert | |
*/ | |
html, body { height: 100%; } | |
body { | |
width: 100%; /* needed for FF */ | |
height: 90%; /* needed for your eyes */ | |
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: 10em; | |
margin: 1em auto; | |
/* 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); | |
} |
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
<div>OMG, I’m centered!</div> |
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
{"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