exhtml
4/20/2017 - 6:19 AM

Vertical/horizontal center sin display table https://css-tricks.com/snippets/sass/centering-mixin/

Vertical/horizontal center sin display table https://css-tricks.com/snippets/sass/centering-mixin/

<div class="parent">
  <div class="child">I'm centered!</div>
</div>
@mixin centerer {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

// Usage

.parent {
  position: relative;
}
.child {
  @include centerer;
}


/* - - - - - More flexible - - - - - - */

@mixin centerer($horizontal: true, $vertical: true) {
  position: absolute;
  @if ($horizontal and $vertical) {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  } @else if ($horizontal) {
    left: 50%;
    transform: translate(-50%, 0);
  } @else if ($vertical) {
    top: 50%;
    transform: translate(0, -50%);
  }
}


// Usage

.child {
  &.both {
    @include centerer;
  }

  &.horizontal {
    @include centerer(true, false);
  }

  &.vertical {
    @include centerer(false, true);
  }
}