Skip to content

Instantly share code, notes, and snippets.

@rotassator
Last active February 11, 2016 00:27
Show Gist options
  • Save rotassator/d94ea71a5717f39e4307 to your computer and use it in GitHub Desktop.
Save rotassator/d94ea71a5717f39e4307 to your computer and use it in GitHub Desktop.
CSS: centre a child block vertically
/*
* Centre a child block vertically within its parent.
* Works in IE9+ and other browsers. http://caniuse.com/#feat=transforms2d
*/
parent {
position: relative; /* create a positioning context */
}
child {
position: absolute;
top: 50%; /* position the top of the element to the middle of the parent */
transform: translateY(-50%); /* move the element up by half its height */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment