Table Elements and Attributes part 5 (rowspan, scope, valign, width)
Table of Content:
The td and th Elements
The <td> and <th> Elements Represent Table Cells.
Remember By default, the contents of a <th> element are usually displayed in a bold font, horizontally aligned in the center of the cell. The content of a <td> element, meanwhile, will usually be displayed left - aligned and not in bold (unless otherwise indicated by CSS or another element).
The rowspan
Attribute
The purpose of the HTML rowspan attribute is to define the number of rows spanned by an individual table cell. The value of the attribute being the number of rows the cell stretches across.
<td rowspan = "2" >
Html code
Live Preview
<th rowspan="3">
html code
Month | Earning | Savings for holiday! |
---|---|---|
January | $100 | |
February | $80 |
Live Preview
The scope
Attribute
The purpose of the HTML scope attribute is to specify the scope for header cells of a table.
HTML scope attribute supports td and th elements. It can be used instead of the headers attribute in basic tables, but does not have much support.
scope = "range"
The objective of this technique is to associate header cells with data cells in complex tables using the scope attribute. The scope attribute may be used to clarify the scope of any cell used as a header. The scope identifies whether the cell is a header for a row, column, or group of rows or columns. The values row, col, rowgroup, and colgroup identify these possible scopes respectively.
The table that follows shows the possible values of the attribute:
Value | Description |
---|---|
col | Defines that the associated cell is a header for a column. |
row | Defines that the associated cell is a header for a row. |
colgroup | Defines that the associated cell is a header for a column group(a group of columns created using the <col> or <colgroup> element ). |
rowgroup | Defines that the associated cell is a header for a row group (a group of cells in a row created using the <thead> , <tbody> , or <tfoot> elements). |
html code
Student Code | Percentage of marks | Grade | Remarks |
---|---|---|---|
S001 | 92 | A+ | Excellent |
S002 | 76 | B+ | Good |
Live Preview
html code
In the following example, column #1 contains serial numbers for rows in the table and the second column contains the key value for the row.
The cells in the second column may then use scope="row"
. The cells in the first row too
are marked up with td and use scope="col"
.
Name | Phone# | Fax# | City | |
---|---|---|---|---|
1. | Joel Garner | 412-212-5421 | 412-212-5400 | Pittsburgh |
2. | Clive Lloyd | 410-306-1420 | 410-306-5400 | Baltimore |
3. | Gordon Greenidge | 281-564-6720 | 281-511-6600 | Houston |
Live Preview
The valign
Attribute
The purpose of the HTML valign attribute is to define the vertical alignment of the content of a table cell.
Possible values are top, middle, bottom, and baseline, each of which was discussed earlier in the chapter in the subsection entitled "The valign Attribute" within the section "The <tr> Element Contains Table Rows."
valign = "top"
Value | Description |
---|---|
top | Sets the vertical alignment of cell content top. |
middle | Sets the vertical alignment of cell content center. |
bottom | Sets the vertical alignment of cell content bottom. |
baseline | If set, the first text line occurs on a baseline common to all cells in the row. |
html code
Student Code | Percentage of marks | Grade | Remarks |
---|---|---|---|
S001 | 92 | A+ | Excellent |
S002 | 76 | B+ | Good |
Live Preview
The width
Attribute
width= "159px"
html code
Name | Roll |
Rambo | CSE13421 |
Rahim | CSE14421 |