Saturday, March 22, 2008

[code] Horizontal and vertical center for a div in CSS

#centerDiv {
position: absolute;
left: 50%;
width: /* width of your div, say 800px */;
margin-left: /* half width of your div and make it negative, so would be -400px */

top: 50%;
height: /* height of your div, say 600px */;
margin-top: /* half heigt of your div and make it negative, so would be -300px */
}


Reference from here