Last active
August 29, 2015 14:20
-
-
Save poteto/ac77d6f463795da182ba to your computer and use it in GitHub Desktop.
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
@mixin centerChildElement($childElement: 'div', $useFlexbox: true) { | |
@if $useFlexbox == true { | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
} @else { | |
position: relative; | |
#{$childElement} { | |
position: absolute; | |
top: 50%; | |
left: 50%; | |
transform: translate(-50%, -50%); | |
} | |
} | |
} | |
/* | |
Centers a child element horizontally and vertically within a parent element. | |
Pass it a valid CSS selector to use. | |
*/ | |
.someParentElement { | |
@include centerChildElement('img'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment