返回到:HTML 元素和有效 DOCTYPES

本节课,我们学习HTML colgroup标签。

标签定义及使用说明

<colgroup> 标签用于对表格中的列进行组合,以便对其进行格式化。

通过使用 <colgroup> 标签,可以向整个列应用样式,而不需要重复为每个单元格或每一行设置样式。

注释:只能在 <table> 元素之内,在任何一个 <caption> 元素之后,在任何一个 <thead>、<tbody>、<tfoot>、<tr> 元素之前使用 <colgroup> 标签。

提示:如果想对 <colgroup> 中的某列定义不同的属性,请在 <colgroup> 标签内使用 <col> 标签。

HTML 4.01 与 HTML5之间的差异

HTML5 中不再支持 HTML 4.01 中的大部分属性。

属性

属性描述
alignleft
right
center
justify
char
HTML5 不支持。规定在列组合中内容的水平对齐方式。
charcharacterHTML5 不支持。规定根据哪个字符来对齐列组中的内容。
charoffnumberHTML5 不支持。规定第一个对齐字符的偏移量。
spannumber规定列组应该横跨的列数。
valigntop
middle
bottom
baseline
HTML5 不支持。定义在列组合中内容的垂直对齐方式。
widthpixels
%
relative_length
HTML5 不支持。规定列组合的宽度。

实例

<colgroup> 和 <col> 标签为表格中的三个列设置了背景色:

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>Web176教程(web176.com)</title> 
</head>
<body>

<table border="1">
  <colgroup>
    <col span="2" style="background-color:red">
    <col style="background-color:yellow">
  </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>5869207</td>
    <td>My first CSS</td>
    <td>$49</td>
  </tr>
</table>

</body>
</html>

全局属性

<colgroup> 标签支持 HTML 的全局属性

事件属性

<colgroup> 标签支持 HTML 的事件属性

返回到:HTML 元素和有效 DOCTYPES

terry

这个人很懒,什么都没有留下~

Share
Published by
terry

Recent Posts

聊聊vue3中的defineProps

在Vue 3中,defineP…

1 周 ago

在 Chrome 中删除、允许和管理 Cookie

您可以选择删除现有 Cooki…

2 周 ago

自定义指令:聊聊vue中的自定义指令应用法则

今天我们来聊聊vue中的自定义…

3 周 ago

聊聊Vue中@click.stop和@click.prevent

一起来学下聊聊Vue中@cli…

4 周 ago

Nginx 基本操作:启动、停止、重启命令。

我们来学习Nginx基础操作:…

4 周 ago

Vue3:手动清理keep-alive组件缓存的方法

Vue3中手动清理keep-a…

1 月 ago