一个表格只能包含一个caption元素,无需是表格的第一个元素,但始终显示在表格上方。
列分组
在表格中,由于表格都是按行组建的,导致对列的操作不太方便,例如为表格的某列定义样式。可以使用colgroup元素来指定列的分组。
<html>
<head>
<style>
#colgroup1{background-color: red}
#colgroup2{background-color: green; font-size=small}
</style>
</head>
<body>
<table width="100%" border="1">
<colgroup id="colgroup1" span="2" ></colgroup>
<colgroup id="colgroup2"></colgroup>
<tr>
<th>ISBN</th>
<th>Title</th>
<th>Price</th>
</tr>
<tr>
<td>3476896</td>
<td>My first HTML</td>
<td>$53</td>
</tr>
<tr>
<td>2489604</td>
<td>My first CSS</td>
<td>$47</td>
</tr>
</table>
</body>
</html>上面的例子中指定了两个列的组,第一个包含前2列,第二个包含剩下的1列,并为不同的分组指定了不同的样式。colgroup的span属性指定扩展几列,如果不指定span属性,也可以指定一个或多个col元素,下面的例子达到了和上面例子一样的效果。
<html>
<head>
<style>
#colgroup1{background-color: red}
#col3{background-color: green; font-size=small}
</style>
</head>
<body>
<table width="100%" border="1">
<colgroup id="colgroup1">
<col id="col1And2" span="2"/>
<col id="col3"/>
</colgroup>
<tr>
<th>ISBN</th>
<th>Title</th>
<th>Price</th>
</tr>
<tr>
<td>3476896</td>
<td>My first HTML</td>
<td>$53</td>
</tr>
<tr>
<td>2489604</td>
<td>My first CSS</td>
<td>$47</td>
</tr>
</table>
</body>
</html>









