HTML <col> 元素 定義表格中的列,并用于定義所有公共單元格上的公共語義。它通常位于 <colgroup>元素內(nèi)。
<colgroup> 和 <col> 標簽為表格中的三個列設(shè)置了背景色:
<!doctype html> <html> <head> <meta charset="UTF-8"> <title>菜鳥教程(cainiaoplus.com)</title> </head> <body> <table> <colgroup> <col span="3" style="background-color:#FFF3E0;"> <col style="background-color:orange;"> </colgroup> <thead> <tr> <th>Item</th> <th>Quantity</th> <th>Price</th> <th>Total</th> </tr> </thead> <tbody> <tr> <td>Oranges</td> <td>45</td> <td>$2</td> <td>$90</td> </tr> </tbody> </table> </body> </html>測試看看 ?/?
在此HTML5文檔示例中,我們創(chuàng)建了具有<colgroup>,<thead>和<tbody>部分的表。在<colgroup>部分中,我們使用了兩個<col>標記。第一個<col>標記將前三列分組,并將這些列的背景色設(shè)置為淺橙色,即#FFF3E0的十六進制值。第二個<col>標簽將第四列分組,并將其背景色設(shè)置為橙色。
IEFirefoxOperaChromeSafari
所有主流瀏覽器都支持 <col> 標簽。
<col>標簽用于<colgroup>部分,以定義列的屬性。
通過使用 <col> 標簽,可以向整個列應用樣式,而不需要重復為每個單元格或每一行設(shè)置樣式。
HTML5 中不再支持 HTML 4.01 中的大部分屬性。
在 HTML 中,<col> 標簽沒有結(jié)束標簽。
在 XHTML 中,<col> 標簽必須被正確的關(guān)閉。
屬性 | 值 | 描述 |
---|---|---|
align | left right center justify char | HTML5 不支持。規(guī)定與 <col> 元素相關(guān)的內(nèi)容的水平對齊方式。 |
char | character | HTML5 不支持。規(guī)定根據(jù)哪個字符來對齊與 <col> 元素相關(guān)的內(nèi)容。 |
charoff | number | HTML5 不支持。規(guī)定第一個對齊字符的偏移量。 |
span | number | 規(guī)定 <col> 元素應該橫跨的列數(shù)。 |
valign | top middle bottom baseline | HTML5 不支持。規(guī)定與 <col> 元素相關(guān)的內(nèi)容的垂直對齊方式。 |
width | % pixels relative_length | HTML5 不支持。Specifies the width of a <col> element |
<col> 標簽支持 HTML 的全局屬性。
<col> 標簽支持 HTML 的事件屬性。