Skip to content

Instantly share code, notes, and snippets.

@poteto
Last active August 29, 2015 14:20
Show Gist options
  • Save poteto/ac77d6f463795da182ba to your computer and use it in GitHub Desktop.
Save poteto/ac77d6f463795da182ba to your computer and use it in GitHub Desktop.
@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