-
-
Save ZeeAgency/2404920 to your computer and use it in GitHub Desktop.
Vertical centering with inline-block + generated-content
This file contains 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
/** | |
* Vertical centering with inline-block + generated-content | |
* Julien Cabanès | |
* based on http://css-tricks.com/centering-in-the-unknown/ | |
*/ | |
html, body { height: 100%; } | |
body { | |
display: inline-block; | |
margin: 0; | |
padding: 0; | |
width: 100%; | |
text-align: center; | |
} | |
body:before { | |
display: inline-block; | |
content: ''; | |
height: 100%; | |
vertical-align: middle; | |
} | |
div { | |
display: inline-block; | |
vertical-align: middle; | |
padding: 1em 1.5em; | |
/* Fallback to look decent w/out Flexbox */ | |
max-width: 10em; | |
/* 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 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 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