I want to show a table of fixed width at the center of browser window. Now I use
<table width="200" align="center">
But Visual Studio 2008 gives warning on this line:
Attribute 'align' is considered outdated. A newer construct is recommended.
What CSS style should I apply to the table to obtain the same layout?
Right-click anywhere inside the table and then choose the “Table Properties” command from the context menu that appears. In the Table Properties window that opens, you can choose left, center, or right alignment by clicking those options in the “Alignment” section.
You need to set the left margin to auto too. That will make the left margin push the table as far right as is allowed by the right margin.
Steven is right, in theory:
the “correct” way to center a table using CSS. Conforming browsers ought to center tables if the left and right margins are equal. The simplest way to accomplish this is to set the left and right margins to “auto.” Thus, one might write in a style sheet:
table { margin-left: auto; margin-right: auto; }
But the article mentioned in the beginning of this answer gives you all the other way to center a table.
An elegant css cross-browser solution: This works in both MSIE 6 (Quirks and Standards), Mozilla, Opera and even Netscape 4.x without setting any explicit widths:
div.centered { text-align: center; } div.centered table { margin: 0 auto; text-align: left; } <div class="centered"> <table> … </table> </div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With