我想在浏览器窗口的中心显示一个固定宽度的表格。现在我用
<table width="200" align="center">
但 Visual Studio 2008 在此行给出警告:
属性“对齐”被认为已过时。建议使用更新的构造。
我应该对表格应用什么 CSS 样式以获得相同的布局?
最佳答案
Steven 是对的,在 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;
}
但是本答案开头提到的文章为您提供了使表格居中的所有其他方法。
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>
关于html - 水平对齐表格的CSS方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/301147/