HTML col和colgroup元素

Of all the tags used with , including those for , perhaps the most neglected is the col element. The easiest way to describe col is by making a comparison to the div tag: col is an element that controls the appearance of other content, while the col tag does not appear on the page itself (or at least not without applied). col allows us to avoid the need to repeatedly apply classes to induvidual table cells.

在与使用的所有标签中,包括那些用于的标签,也许最被忽略的是col元素。 描述col的最简单方法是与div标签进行比较: col是控制其他内容外观的元素,而col标签不会出现在页面本身上(或者至少在没有应用情况下不会出现)。 col允许我们避免重复将类应用于单个表单元格。

World’s Fastest 100m Sprinters, 2012
NameCountryBest Time
Average Time9.66 seconds
Usain BoltJamaica9.58 seconds
Tyson GayUnited States9.69 seconds
Asafa PowellJamaica9.72 seconds
2012年世界上最快的1亿短跑运动员
名称 国家 最好的时间
平均时间 9.66秒
博尔特 牙买加 9.58秒
泰森·盖伊 美国 9.69秒
阿萨法·鲍威尔(Asafa Powell) 牙买加 9.72秒

The <col> tag is integrated into the table structure just after the <caption>. (Note that I’ve removed closing tags that are optional in HTML5 to save space – in XHTML, an opening <col> tag should be matched with a closing </col>).

<col>标记<col> <caption>之后被集成到表结构中。 (请注意,为了节省空间,我删除了HTML5中可选的结束标记–在XHTML中,开始<col>标记应与结束</col>匹配)。

<table id=sprinters>
	<caption>World’s Fastest 100m Sprinters, 2012</caption>
	<col><col><col>
	<thead>
		<tr>
			<th>Name
			<th>Country
			<th>Best Time
	</thead>
	<tfoot>
		<tr>
			<td colspan="2">Average Time
			<td>9.66 seconds
	</tfoot>
	<tbody>
		<tr>
			<td>Usain Bolt
			<td>Jamaica
			<td>9.58 seconds
		<tr>
			<td>Tyson Gay
			<td>United States
			<td>9.69 seconds
		<tr>
			<td>Asafa Powell
			<td>Jamaica
			<td>9.72 seconds
	</tbody>
</table>

This markup has the following CSS applied:

此标记应用了以下CSS

#sprinters {
	border-collapse: collapse;
}
#sprinters caption {
	font-size: larger;
}
#sprinters td, #sprinters th {
	padding: .5rem;
}
#sprinters tfoot tr td {
	border-top: 1px solid #000;
}
#sprinters col:last-child {
	background: #ddd;
}
#sprinters thead {
	background: #000;
	color: #fff;
}

The number of <col> elements must match the number of table cells in each row. You can stretch a <col> to take command of more columns with the <span> attribute:

<col>元素的数量必须与每一行中的表格单元格的数量匹配。 您可以使用<span>属性来拉伸<col>以接受更多列的命令:

<col span="2"><col>

The “count” of <col> elements is now equal to 3, and any style applied to the first <col> element will control the appearance of the first two table columns.

现在, <col>元素的“计数”等于3,并且应用于第一个<col>元素的任何样式都将控制前两个表列的外观。

Table columns can be grouped together using the colgroup element:

可以使用colgroup元素将表列分组在一起:

<colgroup>
	<col><col>
</colgroup>
<col>

Both <col> and <colgroup> can have styles applied to enhance the appearance of tables.

<col><colgroup>都可以应用样式来增强表的外观。

翻译自: https://thenewcode.com/556/The-HTML-col-and-colgroup-elements

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值