-
-
Save helloromero/743a60c856ec469e98f313fe39f284de to your computer and use it in GitHub Desktop.
Center anything horizontally vertically or on both axis in scss
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 anything horizontally, vertically or both (assuming that the parents position is set to relative) | |
// Codepen Example Usage: https://codepen.io/anon/pen/yPbgYW | |
@mixin center($center: 'all') { | |
position: absolute; | |
@if $center == 'all' { | |
top: 50%; | |
left: 50%; | |
transform: translate(-50%, -50%); | |
} @else if $center == 'horizontal' { | |
top: 0; | |
left: 50%; | |
transform: translateX(-50%); | |
} @else if $center == 'vertical' { | |
left: 0; | |
top: 50%; | |
transform: translateY(-50%); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment