Skip to content

Instantly share code, notes, and snippets.

@nashvail
Created May 17, 2016 11:19
Show Gist options
  • Save nashvail/5691f2ca43ccb74bb3f6775b9a13f4e3 to your computer and use it in GitHub Desktop.
Save nashvail/5691f2ca43ccb74bb3f6775b9a13f4e3 to your computer and use it in GitHub Desktop.
Sass Mixin to position child in parent, relative to parent's center
@mixin centerer($horizontal: true, $vertical: true, $offsetH: 0%, $offsetV: 0%) {
position: absolute;
@if ($horizontal and $vertical) {
top: 50% + $offsetV;
left: 50% + $offsetH;
transform: translate(-50%, -50%);
} @else if ($horizontal) {
left: 50% + $offsetH;
transform: translate(-50%, 0);
} @else if ($vertical) {
top: 50% + $offsetV;
transform: translate(0, -50%);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment