Skip to content

Instantly share code, notes, and snippets.

@maxxscho
Last active January 7, 2016 14:58
Show Gist options
  • Save maxxscho/18618c22dca0e21c6a2a to your computer and use it in GitHub Desktop.
Save maxxscho/18618c22dca0e21c6a2a to your computer and use it in GitHub Desktop.
Centering the unknown
// Center a block element width unknown
// height and width horizontally and vertically
// If it doesn't center vertically, play with the spacing.
// <div class="parent">
// <div class="child">....</div>
// </div>
//
// .parent {
// ... your styles here....
// text-align:center; // if you need horizontally spacing
// @include center-vertical;
// }
//
// .child {
// .... your styles here
// }
@mixin center-vertical($spacing: -0.25em) {
&:before {
content: '';
display: inline-block;
height: 100%;
vertical-align: middle;
margin-right: $spacing;
}
> * {
display: inline-block;
vertical-align: middle;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment