在 Visual Studio 中,我看到了这些警告:
- 验证(HTML 5):属性'cellpadding'不是元素'table'的有效属性。
- 验证(HTML 5):属性'cellspacing'不是元素'table'的有效属性。
- 验证(HTML 5):属性'valign'不是元素'td'的有效属性。
- 验证(HTML 5):属性'align'不是元素'td'的有效属性。
如果它们不是 HTML5 中的有效属性,那么在CSS中替换它们的是什么?
答案 0 :(得分:468)
/* cellpadding */
th, td { padding: 5px; }
/* cellspacing */
table { border-collapse: separate; border-spacing: 5px; } /* cellspacing="5" */
table { border-collapse: collapse; border-spacing: 0; } /* cellspacing="0" */
/* valign */
th, td { vertical-align: top; }
/* align (center) */
table { margin: 0 auto; }
答案 1 :(得分:69)
这可以解决您的问题:
td {
/* <http://www.w3.org/wiki/CSS/Properties/text-align>
* left, right, center, justify, inherit
*/
text-align: center;
/* <http://www.w3.org/wiki/CSS/Properties/vertical-align>
* baseline, sub, super, top, text-top, middle,
* bottom, text-bottom, length, or a value in percentage
*/
vertical-align: top;
}
答案 2 :(得分:12)
特定表格
<table style="border-collapse: separate; border-spacing: 10px;" >
<tr>
<td>Hi</td>
<td>Hello</td>
<tr/>
<tr>
<td>Hola</td>
<td>Oi!</td>
<tr/>
</table>
&#13;
答案 3 :(得分:3)
或者,可以用于特定的表
<table style="width:1000px; height:100px;">
<tr>
<td align="center" valign="top">Text</td> //Remove it
<td class="tableFormatter">Text></td>
</tr>
</table>
在外部文件中添加此css
.tableFormatter
{
width:100%;
vertical-align:top;
text-align:center;
}
答案 4 :(得分:-1)
我认为您使用Visual Studio编辑网页。然后我也遇到了同样的问题。问题是,这个元素没有这样的“属性”。
您已将此属性移至样式:
自:
<td valign="top">XXXX</td>
要:
<td style="vertical-align:top;">XXXX</td>