CSS for vertically centering multiple elements.
Created
March 18, 2014 01:13
-
-
Save stanwmusic/9611765 to your computer and use it in GitHub Desktop.
A Pen by Eric.
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 id="box"> | |
<div id="center"> | |
<h1> | |
This content is centered vertically in the gray box. | |
</h1> | |
<h2> | |
The gray box has a varying height. | |
</h2> | |
<p> | |
There are multiple elements in the gray box. | |
</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
@keyframes resize { | |
0% { | |
height: 300px; | |
} | |
50% { | |
height: 500px; | |
} | |
} | |
#box { | |
margin: 20px auto; | |
width: 50%; | |
height: 300px; | |
background-color: #EEE; | |
padding: 0 20px; | |
white-space: nowrap; | |
animation: resize 5s infinite; | |
} | |
#center { | |
vertical-align: middle; | |
display: inline-block; | |
white-space: normal; | |
} | |
#box:after { | |
content: ""; | |
width: 1px; | |
height: 100%; | |
vertical-align: middle; | |
display: inline-block; | |
margin-right: -10px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Demo is here: http://codepen.io/ejsado/pen/bFuBz