DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

The Simplest Way To Horizontally And Vertically Center A DIV Using CSS

08.11.2009
| 3875 views |
  • submit to reddit
        //to put the 100px * 100px div in the center of the screen, often used for login or thickbox.

.centered_div {
	width: 100px;
	height: 100px;
	position: absolute;
	top: 50%;
	left: 50%;
	margin-left: -50px;       /*half of width*/
	margin-top: -50px;        /*half of height*/
	background: red;
}