Created
August 17, 2012 10:46
-
-
Save ralphcrisostomo/3377895 to your computer and use it in GitHub Desktop.
Center an element absolutely and relatively
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
/** | |
author: Ralph Crisostomo | |
*/ | |
@mixin center-element($width, $height) { | |
width:$width; | |
height:$height; | |
position: absolute; | |
top: 50%; | |
left: 50%; | |
margin-top: -($height / 2); | |
margin-left: -($width / 2); | |
} | |
@include center-element(<element width>,<element hieght>); | |
/** Sample */ | |
.container{ | |
width: 100px; | |
height: | |
// position: relative; // Uncomment to center .element inside .container | |
// Will be centered absolutely | |
.element{ | |
width: 50px; | |
height: 50px; | |
@include center-element(50px,50px); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment