转载自https://www.ggbiji.com/html-col-colgroup.html
<col>标签是给表格中一个或多个列定义属性值,而<colgroup>标签是对表格中的列进行组合,从而实现对表格的格式化。<col>标签一般会放在<colgroup>标签中使用,对<colgroup>标签组合的列分别设置样式。<colgroup>标签也可以有样式属性,是对组合的列设置相同的样式,<colgroup>标签设置的样式会被<col>标签设置的样式覆盖。
格式:
<colgroup span="跨几列">
<col 属性1="属性值1" 属性2="属性值2"....../>
<col 属性1="属性值1" 属性2="属性值2"....../>
</colgroup>
实例:
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>html 中< col>标签和< colgroup>标签的区别笔记_PHP笔记</title> </head> <body style="font-size:28px;"> <table width="450" border="1"> <colgroup style="background:red"> </colgroup> <colgroup span="2" style="background:black"> <col style="background:yellow"> <col style="background:red"> </colgroup> <tr><th>学号</th><th>姓名</th><th>成绩</th></tr> <tr><td>01</td><td>张三</td><td>50</td></tr> <tr><td>02</td><td>李四</td><td>90</td></tr> </table> </body> </html>
运行结果: