最近一直在做表格,所以准备把表格的相关知识总结下
1.表格的结构
<table border="" cellspacing="" cellpadding="">
<thead>
<tr>
<th>Header</th>
</tr>
</thead>
<tbody>
<tr>
<td>body</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>foot</td>
</tr>
</tfoot>
</table>
一般包括表头thead, 表体tbody ,表脚tfoot
对于表头来说,th会默认居中加粗;tbody和tfoot只是一个语义理解,没有特殊样式,一般情况下我们不需要写thead,tbody,tfoot标签,浏览器会自动创建很多情况下我们都是默认不写;
对于浏览器解析表格时,table作为整体解析,只有当里面的内容全部加载完时表格才会显示,但是如果我们使用了thead,tbody,tfoot,浏览器则是则会按照分段展示,下载一段展示一段,而且也会优先解析thead,而不论代码顺序,有利于优化;不过只有当表格较大时才推荐使用
2.表格标签
几个不是很常用就需要注意caption,colgroup,col
caption是表格标题,效果类似于这种

colgroup和col一般是成对出现的,一般用于表格列的格式化,colgroup是列的集合,而col则是代表列,通过colgroup,我们可以控制列,比如宽度,颜色等等
<table border="1" cellspacing="0" cellpadding="0">
<caption>我是标题</caption>
<colgroup>
<col width=100px;/>
</colgroup>
<thead>
<tr>
<th>Header</th>
</tr>
</thead>
<tbody>
<tr>
<td>body</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>foot</td>
</tr>
</tfoot>
</table>