Skip to content

Instantly share code, notes, and snippets.

@flauwekeul
Created February 26, 2014 16:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save flauwekeul/9232799 to your computer and use it in GitHub Desktop.
Save flauwekeul/9232799 to your computer and use it in GitHub Desktop.
Sass mixin to vertically center the children of a container
// 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