Skip to content

Instantly share code, notes, and snippets.

@JesseHerrick
Created July 17, 2013 22:32
Show Gist options
  • Save JesseHerrick/6025141 to your computer and use it in GitHub Desktop.
Save JesseHerrick/6025141 to your computer and use it in GitHub Desktop.
Formula for vertically centering things with CSS.
.center {
width: 500px;
position: absolute;
left: 50%;
margin-left: -250px; /* Exactly half of the width. */
}
/*
Full Formula:
margin-left = width/2 if left = 50%
margin-right = width/2 if right = 50%
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment