--- title:
HTML 中的 表格列组(Column Group <colgroup>) 标签用来定义表中的一组列表。
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
内容类别 | 无。 |
---|---|
允许的内容 | If the {{htmlattrxref("span", "colgroup")}} attribute is present: none, it is an {{Glossary("empty element")}}. If the attribute is not present: zero or more {{HTMLElement("col")}} element |
标签省略 | 如果元素的第一个子元素存在且是一个 {{HTMLElement("col")}} 元素,而且在它之前没有省略了结束标签的 {{HTMLElement("colgroup")}} 元素,元素的开始标签可以被省略。 如果之后没有紧跟一个空格或注释,元素的结束标签可以被省略。 |
允许的父元素 | 一个 {{HTMLElement("table")}} 元素。The {{HTMLElement("colgroup")}} must appear after any optional {{HTMLElement("caption")}} element but before any {{HTMLElement("thead")}}, {{HTMLElement("th")}}, {{HTMLElement("tbody")}}, {{HTMLElement("tfoot")}} and {{HTMLElement("tr")}} element. |
允许的 ARIA roles | 无 |
DOM 接口 | {{domxref("HTMLTableColElement")}} |
此标签支持 全局属性。
left
,元素中的内容左对齐center
,元素中的内容居中对齐right
,元素中的内容右对齐justify
,插入空格,使元素中内容两端对齐char
,针对确定的字符,设置一个最小偏移量,来进行布局,通过 {{htmlattrxref("char", "col")}} 和 {{htmlattrxref("charoff", "col")}} 属性进行定义 {{unimplemented_inline(2212)}}。此属性的默认值为 left
。后代 {{HTMLElement("col")}} 元素可以用它们自己的 {{htmlattrxref("align", "col")}} 属性值来重写该属性。
left
, center
, right
或 justify
相同的效果:
td:nth-child(an+b)
的 CSS 选择器,a 是表格中列的总数,b 是当前列在表格中的位列次序号。只有在这个选择器之后, {{cssxref("text-align")}} 属性可以使用。[colspan=n],但这不常用。
char
相同的效果:在 CSS3 中,你可以使用 {{htmlattrxref("char", "colgroup")}} 作为 {{cssxref("text-align")}} 的属性值。 {{unimplemented_inline}} 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" |
char
, this attribute is ignored, though it will still be used as the default value for the {{htmlattrxref("align", "col")}} of the {{HTMLElement("col")}} which are members of this column group.
<colgroup>
element spans. If not present, its default value is 1
.
span
attribute is not permitted if there are one or more <col>
elements within the <colgroup>
.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;top
, which will put the text as close to the top of the cell as it is possible.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 {{cssxref("vertical-align")}} property can be used.[colspan=n]
, though this is not trivial.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.请参考 {{HTMLElement("table")}} 页面以查看 <colgroup>
的示例。
规范 | 状态 | 备注 |
---|---|---|
{{SpecName('HTML WHATWG', 'tabular-data.html#the-colgroup-element', '<colgroup>')}} | {{Spec2('HTML WHATWG')}} | |
{{SpecName('HTML5 W3C', 'tabular-data.html#the-colgroup-element', '<colgroup>')}} | {{Spec2('HTML5 W3C')}} | |
{{SpecName('HTML4.01', 'tables.html#edef-COLGROUP', '<colgroup>')}} | {{Spec2('HTML4.01')}} |
{{Compat("html.elements.colgroup")}}
<col>
元素编写样式时特别有用的 CSS 属性和伪类: