Skip to content

Instantly share code, notes, and snippets.

@tommymarshall
Last active December 20, 2015 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommymarshall/6178535 to your computer and use it in GitHub Desktop.
Save tommymarshall/6178535 to your computer and use it in GitHub Desktop.
I'm using it in this content, where `.trailer__wrap` takes up the full length of the parent element, and `.trailer` element get's vertically aligned center:
%vertically-centered-child {
font-size: 0;
text-align: center;
&:before {
content: '';
display: inline-block;
height: 100%;
vertical-align: middle;
}
> * {
display: inline-block;
font-size: $base-font-size;
vertical-align: middle;
}
}
/* Usage:
.trailer__wrap {
@extend %vertically-centered-child;
bottom: 0;
left: 0;
position: absolute;
right: 0;
top: 0;
}
.trailer {
// Whatever element that I want to be vertically aligned.
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment