Description:
The <col> tag specifies column properties for each column within a <colgroup> element.
The <col> tag is useful for applying styles to entire columns, instead of repeating the styles for each cell, for each row.
The HTML col tag allows authors to group together attribute specifications for table columns. The <col> does not group columns together structurally — that is the role of the <colgroup> element.
Tip:The <col> elements are empty and serve only as a support for attributes.
Differences Between HTML and XHTML:
In HTML the <col> tag has no end tag.
In XHTML, the <col> tag must be properly closed.
Differences Between HTML 4.01 and HTML5:
Most of the attributes in HTML 4.01 are not supported in HTML5.
Example 1:
Code | View | |||
---|---|---|---|---|
<p>This example shows a colgroup that has three columns of different widths:</p>
<table border="1"> |
This example shows a colgroup that has three columns of different widths:
|
Example 2:
Code | View | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
<table> <col style="width: 180px;" span="2"></col> <col style="width: 80px; background: #EEEEEE;"></col> <tr> <th>Name</th> <th>Gender</th> <th>Age</th> </tr> <tr> <td>Richard</td> <td>Male</td> <td>32</td> </tr> <tr> <td>Anna</td> <td>Female</td> <td>18</td> </tr> <tr> <td>Dean</td> <td>Male</td> <td>23</td> </tr> <tr> <td>Sean</td> <td>Male</td> <td>65</td> </tr> </table> |
|
Attributes:
Attribute | Value | Description |
---|---|---|
align |
right left center justify char |
Defines horizontal alignment |
char | character | Defines a character to use to align text on (use with align="char"). |
charoff | pixel | Specifies an alignment offset (either in pixels or percentage value) against the first character as specified with the char attribute. |
span | number | Defines the number of columns the <col> should span |
valign |
bottom middle top baseline |
Defines vertical alignment |
width | pixels or % | Specifies a default width for each column spanned by the current col element |
Standard Attributes:
Attribute | Description |
---|---|
class | Document wide identifier |
dir | Specifies the direction of the text |
id | Document wide identifier |
title | Specifies a title to associate with the element. |
style | Helps to include inline casecadubf style sheet. |
lang | Sets the language code. |
Event Attributes:
Attribute | Description |
---|---|
onclick | Script runs when a mouse click |
ondblclick | Script runs when a mouse double-click |
onmousedown | Script runs when mouse button is pressed |
onmouseup | Script runs when mouse button is released |
onmouseover | Script runs when mouse pointer moves over an element |
onmousemove | Script runs when mouse pointer moves |
onmouseout | Script runs when mouse pointer moves out of an element |
onkeypress | Script runs when key is pressed and released |
onkeydown | Script runs when key is pressed |
onkeyup | Script runs when key is released |
The post HTML col tag appeared first on .