Skip to content

Instantly share code, notes, and snippets.

@jackilyn
Created January 6, 2012 23:08
Show Gist options
  • Save jackilyn/1572874 to your computer and use it in GitHub Desktop.
Save jackilyn/1572874 to your computer and use it in GitHub Desktop.
Center a <div> Horizontally and Vertically
/*
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