HTML Colgroup Tag - Javatpoint
Có thể bạn quan tâm
Introduction:
The table is created as a sequence of rows. Setting a row's attributes affects all cells in that row. But if you want to change the properties of a particular column you have to set the property for each <td> element in a row of that column which is very tedious. So to effect each cell of a particular column in a single row, we use the <colgroup> and <cols> elements. These elements are used to create some advanced features like grouping columns, sharing attributes between aggregate columns, partitioning the table into multiple partitions, etc.
What is <colsgroup> tag?
HTML <colgroup> tag specifies group of column within an HTML table. It is used a parent container of one or more <col> elements to apply different properties in an HTML table. The <colgroup> element is always in the <table> element and usually before the first row definition. The starting tag <colgroup> is essential but the ending tag </colgroup> is optional. By using colgroup> element you can apply formatting to group of columns instead of applying formatting to each column separately.
NOTE: The <colgroup> tag must be used with <table> element after the <caption> and before <thead> or <tbody> elements.
What is <cols> tag?
Like <colgroup> element, the <col> element or tag is also used for formatting columns. This element is always used inside the <colgroup> element. It is an empty element as it contains no contents but only the attributes used for formatting purpose. It is usually used when you need to format columns in the middle differently from the rest of the columns. The attributes that can be used with <cols> element are the same as that of <colsgroup> element.
Syntax
<colgroup> <col> <col> </colgroup>Following are some specifications about the HTML <colgroup> tag
Display | None |
Start tag/End tag | Start tag and End Tag |
Usage | HTML tables |
Now, let us consider an example of a <colsgroup> element in a table containing 3 columns.
Example
<!DOCTYPE html> <html> <head> <title>Colgroup tag</title> </head> <body> <h2>Example of Colgroup Tag</h2> <table border="1"> <colgroup> <col style="background-color: green" width="40"> <col span="2" style="background-color: #ff7256" width="80"> </colgroup> <tr> <th>Sr.No</th> <th>Product</th> <th>Price</th> </tr> <tr> <td>1</td> <td>Rice</td> <td>85</td> </tr> <tr> <td>2</td> <td>Butter</td> <td>260</td> </tr> <tr> <td>3</td> <td>Mango</td> <td>125</td> </tr> </table> </body> </html> Test it NowOutput:
In order to change the properties of a particular column, a list of attributes are available that can use with <colgroup> element. These are generally written as:
Syntax
<colgroup attribute_name = "value">......</colgroup>Following are the various attributes available:
Attribute | Value | Description |
---|---|---|
align |
| It specifies the alignment of the column content. (Not supported in HTML5). |
char | character | It specifies the alignment of the content in a column group to the character. (Not supported in HTML5). |
charoff | number | It sets the number of characters to offset the column data from the alignment character specified by the char attribute. (Not supported in HTML5). |
span | number | The span attribute is used to specify the number of columns that a colgroup should span. The default value of this attribute is 1.For Example:<colgroup align = "center" span ="2">It will horizontally align the contents of the first two columns to the center. |
valign |
| It specifies the vertical alignment of the column group. (Not supported in HTML5). |
width |
| It specifies the width of the group of column. (Not supported in HTML5). |
bgcolor |
| The bgcolor attribute is used to set the background color of the column in the table. The can be represented either by their name or by their hexadecimal equivalent.For Example:<colgroup bgcolor = "green">On specifying this attribute to green value, the first column of the table will have green background.Similarly you can also write it as:<colgroup bgcolor = "#00FF00"> |
Global Attribute
HTML <colgroup> tag supports all Global attributes in HTML.
Event Attribute
HTML <colgroup> tag supports all event attributes in HTML.
Supporting Browsers
Element | Chrome | IE | Firefox | Opera | Safari |
<colgroup> | Yes | Yes | Yes | Yes | Yes |
Từ khóa » Html Table Hide Column Colgroup
-
Why Can't I Hide A Table Column In CSS Using The
Property? -
Hide Columns - Tryit Editor V3.7
-
HTML Table Colgroup - W3Schools
-
: The Table Column Group Element - MDN Web Docs -
Html Table Hidden Column
-
How To Hide Columns In Html Table
-
17 Tables - W3C
-
Hide Table Column In CSS
-
HTML And CSS Tutorial: How-To's And Miscellaneous
-
Show / Hide Column Of React Table - Material Design For Bootstrap
-
Table Colgroup In HTML With Examples - Dot Net Tutorials
-
Hiding Columns - FooTable - GitHub Pages
-
Problem With DT1.10+ Using ColVis And HTML Colgroup - DataTables