-
-
Save joeke/1f121782ff3be93c6872 to your computer and use it in GitHub Desktop.
CSS vertical centering
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
.parent { | |
float: left; | |
height: 200px; | |
width: 200px; | |
background: gray; | |
margin: 0 10px 0 0; | |
} | |
.children { | |
position: relative; | |
top: 50%; | |
transform: translateY(-50%); | |
-ms-transform: translateY(-50%); | |
} | |
.child_1 { | |
height: 30px; | |
background: red; | |
} | |
.child_2 { | |
height: 80px; | |
background: blue; | |
} |
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="parent"> | |
<div class="children child_1"></div> | |
</div> | |
<div class="parent"> | |
<div class="children child_2"></div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://codepen.io/anon/pen/bJlDy