Validation: “th start tag in table body.”

半城伤御伤魂 提交于 2021-02-04 22:11:48

问题


<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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!