HTML <colgroup> Tag

Definitie en gebruik

<colgroup> De tag wordt gebruikt om de indeling van groepen van één of meerdere kolommen in een tabel te bepalen.

Om de stijl toe te passen op alle kolommen<colgroup> De tag is zeer nuttig, omdat je dan niet hoeft te herhalen voor elke cel en elke rij.

Opmerking:<colgroup> De tag moet <table> van de elementen, geplaatst in elke <caption> na de element en elke <thead>en<tbody>en<tfoot> en <tr> voor de element.

Tip:Om <colgroup> Om verschillende eigenschappen voor een kolom in te stellen, gebruik dan <colgroup> Gebruik in de tag <col> tag.

Zie ook:

HTML referentiehandleiding:<col> tag

HTML DOM referentiehandleiding:ColumnGroup object

Voorbeeld

Gebruik de <colgroup> en <col> tags om de achtergrondkleur van drie kolommen in te stellen:

<table>
  <colgroup>
    <col span="2" style="background-color:red">
    <col style="background-color:yellow">
  </colgroup>
  <tr>
    <th>ISBN</th>
    <th>Title</th>
    <th>Price</th>
  </tr>
  <tr>
    <td>3476896</td>
    <td>HTML Basics</td>
    <td>$53</td>
  </tr>
</table>

Try it yourself

Attribute

Attribute Value Description
span Number Specifies the number of columns that the column group should span.

Global attributes

<colgroup> The tag also supports Global attributes in HTML.

event attributes

<colgroup> The tag also supports Event attributes in HTML.

Default CSS settings

Most browsers will display the following default values <colgroup> Element:

colgroup {
  display: table-column-group;
}

Try it yourself

Browser support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support