Previous Message
Next Message

Re: [css-d] Center aligning tables with CSS

Sent by Eric A. Meyer on 24 January 2002 23:11


At 19:55 -0800 1/24/02, Michelle wrote:

>I cannot figure out how to center-align a table within CSS so that my
>page still validates as XHTML strict.  The only option for centering
>I've been able to find is 'text-align: center'.  When I div align
>center, I don't validate properly.  Help!

    <table style="width: 50%; margin: 0 auto;">

By setting an explicit width value, and both the left and right 
margins to 'auto', you get centering[1].  'text-align' only applies 
to the alignment of inline content, not entire block-level elements, 
which is why it isn't centering your table.

[1] CSS2:10.3.3; <http://www.w3.org/TR/REC-CSS2/visudet.html#q6>

--
Eric A. Meyer (http://www.meyerweb.com/eric/), List Mom
"CSS is much too interesting and elegant to be not taken seriously."
   -- Martina Kosloff
Previous Message
Next Message

Message thread: