Spanning Multiple Rows and Cells
Posted by admin | Posted in HTML Tutorial | Posted on 11-08-2010-05-2008
0
rowspan is an attribute to span multiple rows and colspan to span multiple columns.
i.e. with rowspan you can make a row span over multople columns and with colspan you can make a column span over multiple columns.
<th> tag can be used to give header to the columns
Example:
- <table border=”1″>
- <tr>
- <th>Column 1</th>
- <th>Column 2</th>
- <th>Column 3</th>
- </tr>
- <tr><td rowspan=”2″>Row 1 Cell 1</td>
- <td>Row 1 Cell 2</td><td>Row 1 Cell 3</td></tr>
- <tr><td>Row 2 Cell 2</td><td>Row 2 Cell 3</td></tr>
- <tr><td colspan=”3″>Row 3 Cell 1</td></tr>
- </table>
Colspan and Rowspan:
| Column 1 | Column 2 | Column 3 |
| Row 1 Cell 2 | Row 1 Cell 3 | |
| Row 2 Cell 2 | Row 2 Cell 3 | |
| Row 3 Cell 1 | ||
Cell Padding and Spacing
cellpadding and cellspacing attributes are used to adjust the white space on your tables. Spacing defines the width of the border, while padding represents the distance between cell borders and the content within.
Example:
- <table border=”1″ cellspacing=”10″ bgcolor=”rgb(0,255,0)”>
- <tr>
- <th>Column 1</th>
- <th>Column 2</th>
- </tr>
- <tr><td>Row 1 Cell 1</td><td>Row 1 Cell 2</td></tr>
- <tr><td>Row 2 Cell 1</td><td>Row 2 Cell 2</td></tr>
- </table>
Cellspacing and Padding:
| Column 1 | Column 2 |
| Row 1 Cell 1 | Row 1 Cell 2 |
| Row 2 Cell 1 | Row 2 Cell 2 |
And now we will change the cellpadding of the table and remove the cellspacing from the previous example.
Example:
- <table border=”1″ cellpadding=”10″ bgcolor=”rgb(0,255,0)”>
- <tr>
- <th>Column 1</th>
- <th>Column 2</th>
- </tr>
- <tr><td>Row 1 Cell 1</td><td>Row 1 Cell 2</td></tr>
- <tr><td>Row 2 Cell 1</td><td>Row 2 Cell 2</td></tr>
- </table>
Cell Pads:
| Column 1 | Column 2 |
| Row 1 Cell 1 | Row 1 Cell 2 |
| Row 2 Cell 1 | Row 2 Cell 2 |
The value you specify for padding and spacing is interpreted by the browser as a pixel value you. So a value of 10 is simply 10 pixels wide. Most attributes that use numeric values for their measurements use pixels.
Table Tags
| Tag | Description |
| <table> | Defines a table |
| <th> | Defines a table header |
| <tr> | Defines a table row |
| <td> | Defines a table cell |
| <caption> | Defines a table caption |
| <colgroup> | Defines groups of table columns |
| <col> | Defines the attribute values for one or more columns in a table |
| <thead> | Defines a table head |
| <tbody> | Defines a table body |
| <tfoot> | Defines a table footer |
