Created
January 6, 2012 23:08
-
-
Save jackilyn/1572874 to your computer and use it in GitHub Desktop.
Center a <div> Horizontally and Vertically
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
/* | |
Negative margins are exactly half the height and width, which pull the element back into perfect center. | |
Only works with elements of a fixed height/width. | |
*/ | |
.center { | |
position: absolute; | |
left: 50%; | |
top: 50%; | |
width: 300px; | |
height: 300px; | |
margin-left: -150px; | |
margin-top: -150px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment