Skip to content

Instantly share code, notes, and snippets.

@booknara
Created May 7, 2013 21:18
Show Gist options
  • Save booknara/5536207 to your computer and use it in GitHub Desktop.
Save booknara/5536207 to your computer and use it in GitHub Desktop.
Centering div element onto the window.
div.classname {
position: absolute;
left: 50%; /* Start with top left in the center */
top: 50%;
width: 200px; /* The div fixed width... */
height: 100px; /* ...and height */
margin-left: -100px; /* Shift over half the width */
margin-top: -50px; /* Shift up half the height */
}
// Reference : http://stackoverflow.com/questions/2956671/how-to-keep-a-floating-div-centered-on-window-resize-jquery-css
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment