当前位置: html教程 > 04-表格标签 > 阅读正文

col,colgroup标签

2021.5.16.   438 次   946字

在table表格中, 我们很方便的使用tr表示一行,

而col和colgroup作为列和列组使用, 弥补了表格列的空白

col标签表示列

这个标签可以快速的指定一列的样式

<table border="1">
    <col span="2" style="background-color:red">
    <col style="background-color:yellow">
  <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>

列组合标签colgroup

在它包裹的列, 表示一个组合, 可以对组合的列设置统一的属性

<table border="1">
  <colgroup style="background-color:red" >
    <col >
    <col >
  </colgroup>
	<col  style="background-color:yellow">
  <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>

col与colgroup可选属性

它们的可选属性是相同的

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

本篇完,还有疑问?

加入QQ交流群:11500065636 IT 技术交流群