这里主要总结记录下表格的一些属性和简单的样式,方便之后不时之需。html
一、<table>html5
用来定义HTML的表格,具备本地属性 border 表示边框,border属性的值必须为1或空字符串("")。该属性不会控制边框的样式,而是由CSS来控制ide
table元素能够有tr,th,td,thead,tbody,tfoot,colgroup元素spa
二、<tr>3d
用来定义表格的一行。因为HTML表格是面向行的,因此必须分别表示每一行code
tr元素能够在table,thead,tbody和tfoot元素内使用htm
tr元素内能够包含一个或者多个td或th元素blog
它的align,bgcolor等属性已过期,若是要设置属性,请使用CSS设置字符串
三、<td>it
用来定义表格单元格,能够同colspan,rowspan,headers局部属性使用
(1)colspan: 列跨度,该属性规定了单元格可横跨的列数,该属性的值必须是整数
(2)rowspan:行跨度,该属性规定了单元格可横跨的行数,该属性的值必须是整数
(3)headers:该属性的值是一个或多个单元的ID属性值,将单元格与列标题相关联,可用于使用屏幕阅读器
⚠️:每一个表格必须包含以上三个元素
一个简单的实例
<!DOCTYPE html> <html> <body> <table> <tr> <td>A</td> <td>B</td> <td>C</td> </tr> <tr> <td>D</td> <td>E</td> <td>F</td> </tr> </table> </body> </html>
效果以下:
四、<th>
用来定义标题单元格,使咱们有效区分数据及其描述
它同 <td> 元素具备相同的局部属性,二者有以下区别:
五、<thead>
用来定义表格的页眉,表头的包装器。能够定义一行或多行,这些行是 table 元素的列标签
没有thead元素,全部的tr被假定为属于表的主体
六、<tbody>
用来定义表格的主体
七、<tfoot>
用来定义标记表格的页脚
⚠️:
八、<colgroup>
用来定义表列组,可使用其来将样式应用于某个列,固然也可使用下面要说的col元素
具备局部属性 span 的 <colgroup> 表示列组应该横跨的列数。默认是一列,即对表格的一列设置样式
<colgroup>能够包含一个或多个 <col> 元素
九、<col>
用来表示表单个列,建议使用<colgroup>包裹<col>元素而不是<colgroup>直接设置span属性定义组
<col>也具备局部属性span
<col>放在<colgroup>的元素内部,<col>的咩哥实例表示组中的一列。使用该标签能够将样式应用于列的组和该组的单个列
十、<caption>
用来定义表格的标题,每一个表中只能包含一个<caption>元素
一个简单的例子:
<!DOCTYPE html> <html> <head> <style> thead th,tfoot th { text-align: left; background: grey; color: white } tbody th { text-align: right; background: lightgrey; color: grey } /* tbody td { background: greenyellow; } */ #colgroup1 { background-color: blueviolet } #col3 { background-color: yellow; font-size: small } </style> </head> <body> <table> <colgroup id="colgroup1"> <col id="collAnd2" span="2"/> <col id="col3"/> </colgroup> <colgroup id="colgroup2" span="2"></colgroup> <thead> <tr> <th>Rank</th> <th>Name</th> <th>Color</th> <th colspan="2">Size & Votes</th> </tr> </thead> <tfoot> <tr> <th>Rank Footer</th> <th>Name Footer</th> <th>Color Footer</th> <th colspan="2">Size And Votes Footer</th> </tr> </tfoot> <tbody> <tr> <th>Favorite:</th> <td>XML</td> <td>CSS</td> <td>Java</td> <td>IOS</td> </tr> <tr> <th>2nd Favorite:</th> <td>Web</td> <td>HTML5</td> <td>CS</td> <td>460</td> </tr> </tbody> </table> </body> </html>
效果以下: