问题
<table>
<thead>
<th>Table Heading</th>
</thead>
<tbody>
<tr>.....
</tbody>
</table>
When I try to validate this part of code, the validator returns this error:
th start tag in table body.
The table template was copied from getbootstrap.com so I should assume it's valid. What's the problem here? Why is the validator returning this error, and how can I solve it?
回答1:
th
is a table header cell - it needs to be within a tr
:
<table>
<thead>
<tr>
<th>Table Heading</th>
</tr>
</thead>
<tbody>
<tr>.....
</tbody>
</table>
回答2:
The placement of your <th>
element is correct aside from it needing to be placed inside a <tr>
tag as well... as D Stanley mentioned.
This is the full HTML table formatting specified by W3C:
<table>
<thead>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
</thead>
<tfoot>
<tr>
<td>Sum</td>
<td>$180</td>
</tr>
</tfoot>
<tbody>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
</tbody>
</table>
W3C
来源:https://stackoverflow.com/questions/28707330/validation-th-start-tag-in-table-body