Last active
April 26, 2018 20:07
-
-
Save kieranmv95/8c5ff7fd0324814dcf69568bb1be370b to your computer and use it in GitHub Desktop.
Center anything horizontally vertically or on both axis in scss
This file contains 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
I don't like this approach, since it sometimes make the centered element blurry in chrome.