MDN wants to learn about developers like you: https://qsurvey.mozilla.com/s3/MDN-dev-survey

这篇翻译不完整。请帮忙从英语翻译这篇文章

概述

HTML 中的 表格列组(Column Group <colgroup>) 标签用来定义表中的一组列表。

属性

此标签支持 全局属性.

align 已废弃 HTML4.01, 已废弃 HTML5
这个可枚举的属性定义每列元素内容的水平对齐方式,支持的值有:
  • left, 元素中内容左对齐
  • center, 元素中内容居中
  • right, 元素中内容右对齐
  • justify, 插入空格使元素中内容两端对齐
  • char, 针对确定的字符数设置最小偏移量进行布局,通过 charcharoff 属性进行定义 未实现 (查看 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 to char, this attribute is ignored, though it will still be used as the default value for the align 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 the char, in CSS3, you can use the character set using the char attribute as the value of the text-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 is 1.
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>.
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 as bottom.
  • 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 the td: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 the vertical-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 as 0.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 '.'.

文档标签和贡献者

 此页面的贡献者: soyaine, PandaadnaP, FredWe
 最后编辑者: soyaine,