Merging Table Cells
Print This Post
No CommentRelated Reading |
In this little section of our free online web design course, we’re going to learn how to merge table cells by using the “colspan” and “rowspan” attributes along with the <td> tag.
Merging HTML Table Cells Horizontally
In order to merge table cells horizontally, we’ve got to use the “colspan” attribute and the number of cells you wish to merge horizontally. Below is the HTML code we used to build the 9-cell-table in web design lesson 1-05-01:
| <html> <head> </head> <table border=”1″> <tr> <tr> </body> |
As you know, this HTML code produces the below output:
|
Now, if we wish to merge the three cells in the second row horizontally to form one big cell in the middle of our table, we’ll have to use our “colspan” attribute with the value of “3″ as we want to merge 3 cells. We’re going to put the “colspan” attribute into the first <td> tag on that row. The HTML code is below:
| <html> <head> </head> <table border=”1″> <tr> <tr> </body> |
Note that you should not add any more <td> tags inside the middle row to be able to merge all of the three cells. The above HTML code produces the below output:
|
|||||||||
You see how the middle cells merged into one single cell? Great, isn’t it? Now let’s merge table cells vertically by using the “rowspan” attribute!
Merging HTML Table Cells Vertically
Your free online web design course will now merge the middle column (Column 2) in the above 9-cell-table. To do that, we’ll use the “rowspan” attribute inside the first middle <td> tag and remove the other two middle <td> tags from the second and third rows to have one cell that spans three rows! Have a look at the HTML code below to get a clearer picture:
| <html> <head> </head> <table border=”1″> <tr> <tr> </body> |
Notice how I removed the other two middle <td> tags and only left the first and third columns in the second and third rows of the table. The output of the above HTML code is below:
|
If you enjoyed this lesson, please link to it
We’re done! In the next lesson of our online web design course, you’re going to learn how to use tables to create a site layout.








Popular Tags