Profile image for Gabriel Feippe feippe
How to put a div in the middle of the window.
Language
CSS
Tags
center css div
Favorited By
Profile image for kaine smith Profile image for Patrick Westerfeld Profile image for stefan pettge Profile image for Aizan  Fahri Profile image for Tom Hancock Profile image for Gabriel Feippe Profile image for zafer onay Profile image for Joshua Canfield Profile image for Der Dools Profile image for Ben Bytes Profile image for ~ ~ Profile image for Ku Bin Profile image for Mati D Profile image for Greg Berlin Profile image for Mikkel Rask Profile image for Marcus Stephens Profile image for Peter Schneider Profile image for Igor T Profile image for Robert Whetzel Profile image for Kobus Myburgh

Center a DIV with CSS

1 #idOfTheDiv { 2 width: 400px; /* here you put the width that you need */ 3 height: 200px; /* here you put the height that you need */ 4 position:absolute; 5 left:50%; 6 top:50%; 7 margin-left:-200px; /* this number always to be the width divided two in negative */ 8 margin-top:-100px; /* this number always to be the height divided two in negative */ 9 }

Comments

Profile image for Kobus Myburgh bliksempie 2013-11-14

Very nice! Thanks. Helpful!

Profile image for Robert Christian Obias rchristianobias 2014-05-29

another way would be

#idOfTheDiv {
margin: 0 auto;
}