English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
This article introduces the HTML colgroup width attribute, which specifies the width of the column group. Typically, the space occupied by the column group is the space required for its displayed content. The width attribute is used to set a predefined width for the column group.
The <colgroup> element is used to specify that the predefined width of the first column should be200 pixels:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>HTML <colgroup> width Attribute Usage-Basic Tutorial(oldtoolbag.com)>/title> <style>table, th, td { border: 1px solid black;}/style> </head> <body> <table> <colgroup width="200"> <tr> <th>Month</th> <th>Savings</th> </tr> <tr> <td>January</td> <td>$100</td> </tr> <tr> <td>February</td> <td>$80</td> </tr> </table> </body> </html>Test to see ‹/›
IEFirefoxOperaChromeSafari
All major browsers support the width attribute. However, no browser supports relative_length Value.
In HTML5 The <colgroup> width attribute is not supported.
The width attribute specifies the width of the column group.
By default, the space occupied by the column group is the space needed for its content. The width attribute is used to set a predefined width for the column group.
Note:This attribute will be overridden by any width setting in the <col> element.
<colgroup width="pixels|%|relative_lngth">
Value | Description |
---|---|
pixels | Set the width value in pixels (Example: width="50"). |
% | Set the width value in percentage of the enclosing element (Example: width="50%"). |
relative_length | Distribute the available pixels to each part. The first part is set to "1*", the second part is set to "2*". (For example, the width of the table is 100px, the first column group is 20px, the second column group is 50%, then the remaining available pixels are 30px.). Example: if the available pixels are 30px, then you can set the first part to "1*", the second part is "2*", this will be interpreted as 10 and 20 pixels ("1*For the first part,"2*For the second part). |