Created
July 19, 2016 12:31
-
-
Save kovtunos/f29d4b68afe201f2f66b6c89d357d2c5 to your computer and use it in GitHub Desktop.
Center element #mixin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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