Centering Sass Mixin

Sass mixin that will allow you to center horizontally and vertically.

Learn | Sass

Centering Sass Mixin

The following Sass mixin will allow you to center horizontally and vertically assuming the parent is relative positioned.

@mixin centered {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

To use the above Sass mixin, do the follow:

.classname {
  @include centered;
}