1 - 1 of 1 stories

Centering in CSS

Mon Jun 13 23:47:00 +0200 2005
daBlog » Tech » CSS Tips

For those just converting from HTML tables, centering a div horizontally AND vertically in CSS is a huge pain. But alas, here’s a nice way to center a div which works in both I.E. and Firefox/Mozilla.

#mydiv {
  position:relative;
  width:600px;         /* width of your div */
  height:400px;        /* height of your div */
  margin-left:-300px;  /* half of div's width negated */
  left:50%;
  margin-top:-200px;    /* half of div's height negated */
  top:50%;
}
 

1 - 1 of 1 stories