English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Der HTML-<colgroup>-Tag wird verwendet, um eine Gruppe von Spalten in einer Tabelle zu definieren, sodass Sie das Format auf die Gruppe anwenden oder Klassen hinzufügen können, anstatt jedes einzelne Zelle zu formatieren. Dieser Tag wird auch als <colgroup>-Element bezeichnet.
<colgroup> und <col>-Tags haben die Hintergrundfarbe für vier Spalten im Tisch festgelegt:
!doctype html> <html> <head> <meta charset="UTF-8"> <title>HTML5 colgroup标签的使用(基础教程网 oldtoolbag.com)</title> </head> <body> <table> <colgroup> <col span="3" style="background-color:#FFF9C4"> <col style="background-color:yellow;"> </colgroup> <thead> <tr> <th>Item</th> <th>Quantity</th> <th>Price</th> <th>Total</th> </tr> </thead> <tbody> <tr> <td>Bananas</td> <td>5</td> <td>$12</td> <td>$60</td> </tr> </tbody> </table> </body> </html>Testen Sie, um zu sehen ‹/›
In diesem HTML5In der Dokumentbeispiel haben wir einen Tisch mit <colgroup>, <thead> und <tbody>-Teilen erstellt. Im <colgroup>-Teil haben wir zwei <col>-Tags verwendet. Der erste <col>-Tag gruppiert die ersten drei Spalten und setzt die Hintergrundfarbe dieser Spalten auf #FFF9C4. Der zweite <col>-Tag gruppiert die vierte Spalte und setzt die Hintergrundfarbe auf gelb.
IEFirefoxOperaChromeSafari
Alle gängigen Browser unterstützen das <colgroup>-Tag.
Das HTML <colgroup>-Element befindet sich im HTML-Tisch innerhalb des <body>-Tags.
Das <colgroup>-Tag wird verwendet, um die Spalten in einem Tisch zu kombinieren, um sie zu formatieren.
Das <colgroup>-Tag muss nach dem <caption>-Tag im Tisch auftreten, aber vor dem <thead>, <tr>, <th>, <tbody> und <tfoot>-Tag.
Durch die Verwendung des <colgroup>-Tags können Sie Stile für das gesamte Kolonnenbereich anwenden, ohne für jeden Zelle oder jede Zeile wiederholt Stile zu setzen.
Hint:If you want to define different attributes for a specific column within <colgroup>, use <col> Tags.
HTML5 No longer supports HTML 4.01 Most of the attributes
Attribute | Value | Description |
---|---|---|
align | left right center justify char | HTML5 Not supported. Specifies the horizontal alignment of the content within the column group. |
char | character | HTML5 Not supported. Specifies which character to align the content within the column group by. |
charoff | number | HTML5 Not supported. Specifies the offset of the first alignment character. |
span | number | Specifies the number of columns that the column group should span. |
valign | top middle bottom baseline | HTML5 Not supported. Defines the vertical alignment of the content within the column group. |
width | pixels % relative_length | HTML5 Not supported. Specifies the width of the column group. |
Support for <colgroup> Tag Global Attributes of HTML.
Support for <colgroup> Tag HTML Event Attributes.