--- title:
{{HTMLRef}}
HTML <col>
元素 定义表格中的列,并用于定义所有公共单元格上的公共语义。它通常位于{{HTMLElement("colgroup")}}元素内。
此元素允许使用CSS进行样式列,但只有少数属性将对该列产生影响(请参阅列表的CSS 2.1规范)。
该元素包含一些全局属性 全局属性.
left
, aligning the content to the left of the cellcenter
, centering the content in the cellright
, aligning the content to the right of the celljustify
, inserting spaces into the textual content so that the content is justified in the cellchar
, aligning the textual content on a special character with a minimal offset, defined by the {{htmlattrxref("char", "col")}} and {{htmlattrxref("charoff", "col")}} attributes {{unimplemented_inline(2212)}}.If this attribute is not set, its value is inherited from the {{htmlattrxref("align", "colgroup")}} of the {{HTMLElement("colgroup")}} element this <col>
element belongs too. If there are none, the left
value is assumed.
left
, center
, right
or justify
values:
td:nth-child(an+b)
CSS selector 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("text-align")}} property can be used.[colspan=n]
, though this is not trivial.char
value, in CSS3, you can use the value of the {{htmlattrxref("char", "col")}} as the value of the {{cssxref("text-align")}} property {{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.
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 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")}} 页面 <col>
标签的示例.
Specification | Status | Comment |
---|---|---|
{{SpecName('HTML WHATWG', 'tabular-data.html#the-col-element', '<col>')}} | {{Spec2('HTML WHATWG')}} | |
{{SpecName('HTML5 W3C', 'tabular-data.html#the-col-element', '<col>')}} | {{Spec2('HTML5 W3C')}} | |
{{SpecName('HTML4.01', 'struct/tables.html#h-11.2.4.2', '<col>')}} | {{Spec2('HTML4.01')}} |
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 1.0 | {{CompatGeckoDesktop("1.0")}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
align/valign attribute |
{{CompatUnknown}} | {{CompatNo}} {{bug(915)}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
char/charoff attribute |
{{CompatUnknown}} | {{CompatNo}} {{bug(2212)}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
bgcolor attribute |
{{CompatUnknown}} | {{CompatNo}} | {{CompatVersionUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | {{CompatUnknown}} | {{CompatGeckoMobile("1.0")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
align/valign attribute |
{{CompatUnknown}} | {{CompatNo}} {{bug(915)}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
char/charoff attribute |
{{CompatUnknown}} | {{CompatNo}} {{bug(2212)}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
bgcolor attribute |
{{CompatUnknown}} | {{CompatNo}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
<col>
element:
{{ HTMLRef }}