Last active
December 19, 2015 10:29
-
-
Save roberto/5940958 to your computer and use it in GitHub Desktop.
Centering Percentage Width/Height Elements
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
/* | |
* http://css-tricks.com/centering-percentage-widthheight-elements/ | |
*/ | |
.center { | |
position: absolute; | |
left: 50%; | |
top: 50%; | |
/* | |
Nope =( | |
margin-left: -25%; | |
margin-top: -25%; | |
*/ | |
/* | |
Yep! | |
*/ | |
transform: translate(-50%, -50%); | |
/* | |
Not even necessary really. | |
e.g. Height could be left out! | |
*/ | |
width: 40%; | |
height: 50%; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://css-tricks.com/centering-percentage-widthheight-elements/