Centering Block Level Elements (eg if using tables for formatting)
By Oli
At 7:21 AM · Thursday, 27 February · 2003
To CSS · Coding
There doesn’t seem to be anything to specifically replace the depreciated align=center tag for block-level elements in CSS, only alignment for text. If you are still using a table-based layout and want to center the enclosing table (or a div if you moved on from tables), this CSS seems to be the standards-friendly way:table#container { width: 780px; margin: auto; }
The table should now automatically get extra space assigned equally to the left and right margins if the user’s browser window is wider than the main table’s width (here 780px). This works on most modern browsers, with the notable millstones of NN4 and MSIE 5 (Win).
Idea from WebMasterWorld - there’s a link to more at the bottom of that thread. However for the real dirt check out theodorakis.net, which outlines multiple methods and their results (including ugly hacks that make even millstones swim ;-)