Using CSS tables to vertical align center content.
Created
April 10, 2014 15:00
-
-
Save eddiemoore/10391304 to your computer and use it in GitHub Desktop.
A Pen by Ed Moore.
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 class="container"> | |
<div class="inner"> | |
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p> | |
</div> | |
</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
// Works in IE8+ !!! |
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
html, body { | |
padding: 0; | |
margin: 0; | |
height: 100%; | |
} | |
p { | |
margin: 0; | |
} | |
.container { | |
height: 100%; | |
background: maroon; | |
} | |
.inner { | |
margin: 0 auto; | |
padding: 10px; | |
width: 200px; | |
background: white; | |
} | |
/* Where the magic happens */ | |
body { | |
display: table; | |
width: 100%; | |
} | |
.container { | |
display: table-cell; | |
vertical-align: middle; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment