Horje
How to create HTML <colgroup> Tag

The <colgroup> tag specifies a group of one or more columns in a table for formatting.

The <colgroup> tag is useful for applying styles to entire columns, instead of repeating the styles for each cell, for each row.

Note: The <colgroup> tag must be a child of a <table> element, after any <caption> elements and before any <thead>, <tbody>, <tfoot>, and <tr> elements.

Tip: To define different properties to a column within a <colgroup>, use the <col> tag within the <colgroup> tag.


How to create HTML <colgroup> Tag

Set the background color of the three columns with the <colgroup> and <col> tags
index.html
Example: HTML
 <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>My first HTML</td>
    <td>$53</td>
  </tr>
</table> 

Output should be:

How to create HTML <colgroup> Tag

What Type of Browsers will Support for HTML <colgroup> Tag

Following Browser will support for it.

Output should be:

What Type of Browsers will Support for HTML <colgroup> Tag

Attributes for HTML <colgroup> Tag

Attribute Value Description
span number Specifies the number of columns a column group should span

How to set Default CSS Settings for HTML <colgroup> Tag

Most browsers will display the <colgroup> element with the following default values
index.html
Example: HTML
<style>
table, th, td {
  border: 1px solid black;
}

colgroup {
  display: table-column-group;
} 
</style>

Output should be:

How to set Default CSS Settings for HTML <colgroup> Tag

How to add HTML <colgroup> span Attribute

Set the background color of the first two columns using the <colgroup> span attribute:

Definition and Usage

The span attribute defines the number of columns a <colgroup> element should span.

Tip: To define different properties to a column within a <colgroup>, use the <col> tag within the <colgroup> tag.

Browser Support

Syntax

<colgroup span="number">

Attribute Values

Value Description
number Sets the number of columns a column group should span
index.html
Example: HTML
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
  border: 1px solid black;
}
</style>
</head>
<body>

<h1>The colgroup span attribute</h1>

<table>
  <colgroup span="2" style="background:red"></colgroup>
  <tr>
    <th>ISBN</th>
    <th>Title</th>
    <th>Price</th>
  </tr>
  <tr>
    <td>3476896</td>
    <td>My first HTML</td>
    <td>$53</td>
  </tr>
  <tr>
    <td>5869207</td>
    <td>My first CSS</td>
    <td>$49</td>
  </tr>
</table>

</body>
</html>

Output should be:

How to add HTML <colgroup> span Attribute





Category:
Web Tutorial
Sub Category:
HTML Tag
Uploaded by:
Admin


Read Article
https://develop.horje.com/learn/1434/reference