这篇翻译不完整。请帮忙从英语翻译这篇文章。
概述
HTML 中的 表格列组(Column Group <colgroup>) 标签用来定义表中的一组列表。
- 内容类别无
- 允许内容 If the
span
attribute is present: none, it is an empty element.
If the attribute is not present: zero or more<col>
element - Tag omission The start tag may be omitted, if it has a
<col>
element as its first child and if it is not preceded by a<colgroup>
whose end tag has been omitted.
The end tag may be omitted, if it is not followed by a space or a comment. - 允许的父元素
<table>
元素. The<colgroup>
must appear after any optional<caption>
element but before any<thead>
,<th>
,<tbody>
,<tfoot>
and<tr>
element. - DOM interface
HTMLTableColElement
属性
此标签支持 全局属性.
align
已废弃 HTML4.01, 已废弃 HTML5- 这个可枚举的属性定义每列元素内容的水平对齐方式,支持的值有:
-
left
, 元素中内容左对齐center
, 元素中内容居中right
, 元素中内容右对齐justify
, 插入空格使元素中内容两端对齐char
, 针对确定的字符数设置最小偏移量进行布局,通过char
和charoff
属性进行定义 未实现 (查看 bug 2212)。
此属性默认值为
left
。后代的<col>
元素可以用它们自己的align
属性值重写该属性。小贴士: 不要使用这个属性,它在最新的标准中已经不被支持。- 若要实现与
left
,center
,right
或justify
相同的效果:- 不要为一个
<colgroup>
元素选择器设置text-align
属性.,因为<td>
元素并不是<colgroup>
元素的后代,不继承于它。 - 如果表格不使用
colspan
属性,每列用一个td:nth-child(an+b)
的 CSS 选择器,a 是表格中列的总数,b 是当前列在表格中的位列次序号。只有在这个选择器之后,text-align
属性可以使用。 - 如果表格使用了
colspan
属性,可以通过合并足够多的属性选择器来实现同样的效果,比如[colspan=n],但这不常用。
- 不要为一个
- 若要实现与
char
相同的效果:在 CSS3 中,你可以使用char
作为text-align
的属性值。 未实现
bgcolor
- 这个属性用于定义列组中的每一个列成员的背景颜色。在 sRGB 的定义中,它是一个以 '#' 开头的 6 位 16 进制值,有 16 个预定义的表示颜色的字符串可以使用,如下所示:
black
= "#000000"green
= "#008000"silver
= "#C0C0C0"lime
= "#00FF00"gray
= "#808080"olive
= "#808000"white
= "#FFFFFF"yellow
= "#FFFF00"maroon
= "#800000"navy
= "#000080"red
= "#FF0000"blue
= "#0000FF"purple
= "#800080"teal = "#008080"
fuchsia
= "#FF00FF"aqua
= "#00FFFF"小贴士: 不要使用这个并未标准化的属性,它只在 IE 的某些版本中生效,<colgroup>
标签应该使用 CSS 定义样式。要实现和 bgcolor 属性相似的效果,可以在相关的<td>
标签上使用background-color
属性。
char
已废弃 HTML4.01, 已废弃 HTML5- This attribute specifies the alignment of the content in a column group to a character. Typical values for this include a period (.) when attempting to align numbers or monetary values. If
align
is not set tochar
, this attribute is ignored, though it will still be used as the default value for thealign
of the<col>
which are members of this column group.Note: Do not use this attribute as it is obsolete (and not supported) in the latest standard. To achieve the same effect as thechar
, in CSS3, you can use the character set using thechar
attribute as the value of thetext-align
property 未实现.
charoff
已废弃 HTML4.01, 已废弃 HTML5- This attribute is used to indicate the number of characters to offset the column data from the alignment character specified by the char attribute.
Note: Do not use this attribute as it is obsolete (and not supported) in the latest standard.
span
- This attribute contains a positive integer indicating the number of consecutive columns the
<colgroup>
element spans. If not present, its default value is1
.Note: This attribute is applied on the attributes of the column group, it has no effect on the CSS styling rules associated with it or, even more, to the cells of the column's members of the group.- The
span
attribute may not be present if there are one or more<col>
elements within the<colgroup>
.
- The
valign
已废弃 HTML4.01, 已废弃 HTML5- This attribute specifies the vertical alignment of the text within each cell of the column. Possible values for this attribute are:
baseline
, which will put the text as close to the bottom of the cell as it is possible, but align it on the baseline of the characters instead of the bottom of them. If characters are all of the size, this has the same effect asbottom
.bottom
, which will put the text as close to the bottom of the cell as it is possible;middle
, which will center the text in the cell;- and
top
, which will put the text as close to the top of the cell as it is possible.
Note: Do not use this attribute as it is obsolete (and not supported) in the latest standard:- Do not try to set the
vertical-align
property on a selector giving a<colgroup>
element. Because<td>
elements are not descendant of the<colgroup>
element, they won't inherit it. - If the table doesn't use a
colspan
attribute, use thetd:nth-child(an+b)
CSS selector per column, where a is the total number of the columns in the table and b is the ordinal position of the column in the table. Only after this selector thevertical-align
property can be used. - If the table does use a
colspan
attribute, the effect can be achieved by combining adequate CSS attribute selectors like[colspan=n]
, though this is not trivial.
width
in HTML5- This attribute specifies a default width for each column in the current column group. In addition to the standard pixel and percentage values, this attribute might take the special form
0*
, which means that the width of each column in the group should be the minimum width necessary to hold the column's contents. Relative widths such as0.5*
also can be used.
Examples
Please see the <table>
page for examples on <colgroup>
.
Specifications
Specification | Status | Comment |
---|---|---|
WHATWG HTML Living Standard <colgroup> |
Living Standard | |
HTML5 <colgroup> |
Recommendation | |
HTML 4.01 Specification <colgroup> |
Recommendation |
Browser compatibility
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 1.0 | 1.0 (1.7 or earlier) | (Yes) | (Yes) | (Yes) |
align/valign attribute |
? | 未实现 bug 915 | ? | ? | ? |
char/charoff attribute |
? | 未实现 bug 2212 | ? | ? | ? |
bgcolor attribute |
? | 未实现 | (Yes) | ? | ? |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | ? | 1.0 (1.0) | ? | ? | ? |
align/valign attribute |
? | 未实现 bug 915 | ? | ? | ? |
char/charoff attribute |
? | 未实现 bug 2212 | ? | ? | ? |
bgcolor attribute |
? | 未实现 | ? | ? | ? |
See also
- Other table-related HTML Elements:
<caption>
,<col>
,<table>
,<tbody>
,<td>
,<tfoot>
,<th>
,<thead>
,<tr>
; - CSS properties and pseudo-classes that may be specially useful to style the
<col>
element:- the
width
property to control the width of the column; - the
:nth-child
pseudo-class to set the alignment on the cells of the column; - the
text-align
property to align all cells content on the same character, like '.'.
- the