HTML无效验证

  • 本文关键字:验证 无效 HTML html
  • 更新时间 :
  • 英文 :


HTML:

<table border="1" width="100%">
    <tr>
        <th style= "width: 10%"> Quantity </th>
        <th style= "width: 47%"> Info </th>
    </tr>
</table>

我尝试使用XHTML1.0Strict进行验证,但它告诉我,在这个HTML版本中,width元素没有属性样式。有没有其他方法可以在没有验证问题的情况下编写宽度?

table上的width属性不会导致XHTML 1.0的验证问题。但是,如果您出于其他原因想要去掉它,您可以用CSS代码来替换它,该代码将width属性设置为值100%。一个简单的方法是用具有适当值的style属性替换属性:

<table border="1" style="width: 100%">

但是,通常最好使用外部样式表,或者至少使用style元素,而不是style属性。

其他答案也解决了替换border="1"属性的问题,尽管没有要求这样做。它会稍微复杂一些,因为该属性也会影响单元格之间的边界;请参阅我的"将表示HTML映射到CSS"。

我建议为表分配一个id,然后在外部CSS样式表中对其进行样式设置。但这应该足以验证:

<table style="border: 1px solid black; width: 100%;">
    <tr style="border: 1px solid black;">
        <th style="width: 10%; border: 1px solid black;"> Quantity </th>
        <th style="width: 47%; border: 1px solid black;"> Info </th>
    </tr>
</table>

使用CSS定义widthborder:

HTML:

<table>
<tr>
    <th class="q"> Quantity </th>
    <th class="i"> Info </th>
</tr>
</table>

CSS:

table{
    width:100%;
    border: 1px solid magenta;
}
.q{
    width: 10%;
}
.i{
    width: 47%;
}

最新更新