Skip to content

Instantly share code, notes, and snippets.

@benjamingsmith
Last active February 16, 2017 01:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benjamingsmith/53550e8d92a7c2b27e5e to your computer and use it in GitHub Desktop.
Save benjamingsmith/53550e8d92a7c2b27e5e to your computer and use it in GitHub Desktop.
Center items with SASS mixins
// to use: @include centerCenter;
// make sure the element has position: absolute, relative or fixed
@mixin centerCenter {
left: 50%;
top: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
@mixin vertCenter {
top: 50%;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
}
@mixin horzCenter {
left: 50%;
-webkit-transform: translateX(-50%);
-ms-transform: translateX(-50%);
transform: translateX(-50%);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment