Thursday, December 4, 2008

Vertically & Horizontally Centered <div>

Ran across this beautiful CSS example of a perfectly centered <div>:


#mydiv
{
position:absolute;
top: 50%;
left: 50%;
width:30em;
height:18em;
margin-top: -9em; /*set to a negative number 1/2 of your height*/
margin-left: -15em; /*set to a negative number 1/2 of your width*/
}

No comments: