<colgroup> - HTML(超文本标记语言) 编辑

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
标签省略如果元素的第一个子元素存在且是一个 <col> 元素,而且在它之前没有省略了结束标签的 <colgroup> 元素,元素的开始标签可以被省略。
如果之后没有紧跟一个空格或注释,元素的结束标签可以被省略。
允许的父元素一个 <table> 元素。The <colgroup> must appear after any optional <caption> element but before any <thead>, <th>, <tbody>, <tfoot> and <tr> element.
允许的 ARIA roles
DOM 接口HTMLTableColElement

属性

此标签支持 全局属性

align 已废弃 HTML4.01, 已废弃 HTML5
这个可枚举的属性定义每一列的元素内容的水平对齐方式,支持的值有:
  • left,元素中的内容左对齐
  • center,元素中的内容居中对齐
  • right,元素中的内容右对齐
  • justify,插入空格,使元素中内容两端对齐
  • char,针对确定的字符,设置一个最小偏移量,来进行布局,通过 charcharoff 属性进行定义 未实现 (查看 bug 2212)。

此属性的默认值为 left。后代 <col> 元素可以用它们自己的 align 属性值来重写该属性。

小贴士: 不要使用这个属性,它在最新的标准中已经不被支持。
  • 若要实现与 left, center, rightjustify 相同的效果:
    • 不要为一个 <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 is not permitted 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 已废弃 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.

示例

请参考 <table> 页面以查看 <colgroup> 的示例。

规范

规范状态备注
HTML Living Standard
<colgroup>
Living Standard
HTML5
<colgroup>
Recommendation
HTML 4.01 Specification
<colgroup>
Recommendation

浏览器兼容性

BCD tables only load in the browser

The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.

参见

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:75 次

字数:19444

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文