Skip to content

Instantly share code, notes, and snippets.

@joeke
Created August 13, 2014 11:00
Show Gist options
  • Save joeke/1f121782ff3be93c6872 to your computer and use it in GitHub Desktop.
Save joeke/1f121782ff3be93c6872 to your computer and use it in GitHub Desktop.
CSS vertical centering
.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;
}
<div class="parent">
<div class="children child_1"></div>
</div>
<div class="parent">
<div class="children child_2"></div>
</div>
@joeke
Copy link
Author

joeke commented Aug 13, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment