Skip to content

Instantly share code, notes, and snippets.

@kovtunos
Created July 19, 2016 12:31
Show Gist options
  • Select an option

  • Save kovtunos/f29d4b68afe201f2f66b6c89d357d2c5 to your computer and use it in GitHub Desktop.

Select an option

Save kovtunos/f29d4b68afe201f2f66b6c89d357d2c5 to your computer and use it in GitHub Desktop.
Center element #mixin
// Center element.
// https://css-tricks.com/snippets/sass/centering-mixin/
//
// Usage:
// Arguments: horizontal, vertical
// Note: parent div should be in relative position.
//
// @include centered();
// @include centered(true, false);
// @include centered(false, true);
@mixin centered($horizontal: true, $vertical: true) {
position: absolute;
@if ($horizontal and $vertical) {
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
} @else if ($horizontal) {
left: 50%;
transform: translate(-50%, 0);
} @else if ($vertical) {
top: 50%;
transform: translate(0, -50%);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment