Last active
February 11, 2016 00:27
-
-
Save rotassator/d94ea71a5717f39e4307 to your computer and use it in GitHub Desktop.
CSS: centre a child block vertically
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
/* | |
* 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