Created
February 26, 2014 16:15
-
-
Save flauwekeul/9232799 to your computer and use it in GitHub Desktop.
Sass mixin to vertically center the children of a container
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
// Inspired by http://css-tricks.com/vertically-center-multi-lined-text/ | |
@mixin vertical-center-children($height: auto, $children: ':first-child') { | |
display: table; | |
height: $height; | |
#{$children} { | |
display: table-cell; | |
vertical-align: middle; | |
} | |
} | |
/* Example usage: | |
HTML: | |
<div class="container"> | |
<div class="child">This div gets vertically centered :)</div> | |
</div> | |
SCSS: | |
.container { | |
@include vertical-center-children(200px); | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment