Skip to content

Instantly share code, notes, and snippets.

@roberto
Last active December 19, 2015 10:29
Show Gist options
  • Save roberto/5940958 to your computer and use it in GitHub Desktop.
Save roberto/5940958 to your computer and use it in GitHub Desktop.
Centering Percentage Width/Height Elements
/*
* 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%;
}
@roberto
Copy link
Author

roberto commented Jul 6, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment