本文翻译自:What replaces cellpadding, cellspacing, valign, and align in HTML5 tables?
In Visual Studio , I'm seeing these warnings: 在Visual Studio中 ,我看到这些警告:
Validation (HTML 5): Attribute 'cellpadding' is not a valid attribute of element 'table'. 验证(HTML 5):属性“cellpadding”不是元素“table”的有效属性。 Validation (HTML 5): Attribute 'cellspacing' is not a valid attribute of element 'table'. 验证(HTML 5):属性'cellspacing'不是元素'table'的有效属性。 Validation (HTML 5): Attribute 'valign' is not a valid attribute of element 'td'. 验证(HTML 5):属性'valign'不是元素'td'的有效属性。 Validation (HTML 5): Attribute 'align' is not a valid attribute of element 'td'. 验证(HTML 5):属性'align'不是元素'td'的有效属性。If they are not valid attributes in HTML5 , what replaces them in CSS? 如果它们不是HTML5中的有效属性,那么在CSS中替换它们的是什么?
参考:https://stackoom.com/question/PNb7/什么取代了HTML-表格中的cellpadding-cellspacing-valign和align
This should solve your problem: 这应该可以解决您的问题:
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; }Alternatively, can use for particular table 或者,可以用于特定的表
<table style="width:1000px; height:100px;"> <tr> <td align="center" valign="top">Text</td> //Remove it <td class="tableFormatter">Text></td> </tr> </table>Add this css in external file 在外部文件中添加此css
.tableFormatter { width:100%; vertical-align:top; text-align:center; }On particular table 在特定的桌子上
<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>I think you are using Visual Studio to edit web page. 我认为您正在使用Visual Studio编辑网页。 Then I also faced the same issue. 然后我也遇到了同样的问题。 The thing is, there is no such 'attribute' for this element. 问题是,这个元素没有这样的'属性'。
You have you move this attribute to style: 您已将此属性移动到样式:
From: 从:
<td valign="top">XXXX</td>To: 至:
<td style="vertical-align:top;">XXXX</td>