这两个标签看上去比较简单,单从词义上分析可以解释为列或者列组,两个标签可以一起使用也可以分开使用,都是成立的,两者是有细微差别的,<colgroup> 标签用于对表格中的列进行组合,以便对其进行格式化,<colgroup> 标签只能在 table 元素中使用。而<col> 标签为表格中一个或多个列定义属性值,只能在table或者<colgroup>标签中使用。相关属性是一样的,align(right 、left、center、justify、char)、char(character)、charoff(number)、span(number)、valign(top、middle、bottom、baseline)、width,其中有些属性浏览器是不兼容的。不过经测试发现其字体样式不能改变,只能改变表格样式。
代码示例:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>SEO精学网</title>
</head>
<body>
<table border="1">
<colgroup span="2" style="background-color:#00ff00;"></colgroup>
<tr>
<th>1</th>
<th>2</th>
<th>3</th>
</tr>
<tr>
<th>1</th>
<th>2</th>
<th>3</th>
</tr>
</table>
<table border="1">
<col span="2" style="background-color:#ff0000;">
<tr>
<th>1</th>
<th>2</th>
<th>3</th>
</tr>
<tr>
<th>1</th>
<th>2</th>
<th>3</th>
</tr>
</table>
</body>
</html>
|
运行结果:

顶一下
(1)
踩一下
(0)