Skip to content

Instantly share code, notes, and snippets.

@chrisslater
Last active December 27, 2015 13:39
Show Gist options
  • Save chrisslater/7334569 to your computer and use it in GitHub Desktop.
Save chrisslater/7334569 to your computer and use it in GitHub Desktop.
Vertically align an element within container, using the before method.
// Sourced from: http://css-tricks.com/centering-in-the-unknown/
@mixin element-align-center($child-element, $width-of-child) {
& {
vertical-align: middle;
display:inline-block;
}
&:before {
content: "";
display: inline-block;
height: 100%;
vertical-align: middle;
}
& #{$child-element} {
width: $width-of-child;
vertical-align: middle;
display:inline-block;
padding-top: 0;
margin-left: -0.25em;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment