Oh Happy Day! More HTML Table fun! My hubby is assisting us once again with HTML Tables Part II. Are we lucky girls or what? He’s a great teacher with this technical jibber jabber and seems to make it a little more understandable than some tutorials, you know, the ones that just simply make you go cross-eyed {giggle}. So, let’s now learn how to add some spice to our tables.
Those of you who have worked in Microsoft Excel may be familiar with the “Merge Cells” feature. For those not familiar with the feature, it allows you to take two (or more) cells and merge them in to one cell. The width of the merged cell is the same as the combined width of the two (or more) individual cells. HTML tables provide a similar function with the colspan option.
The Basics of “Merging” Cells
In the original post, {DIY} HTML Tables, we built a basic two row and two column table to align images of the same size. But now you’re bored with four square format and want to add some variety to the table. What if you want to use an image that stretches across the width of two column? Well, we can do this using the colspan option.
The code below shows the original structure of a two row and two column table.
<table border = "0"> <tbody> <tr> <td>Row 1 Column 1</td> <td>Row 1 Column 2</td> </tr> <tr> <td>Row 2 Column 1</td> <td>Row 2 Column 2</td> </tr> </tbody> </table>
We modify this code with the addition of the colspan option placing it within the <td> tag. We use colspan="2" because we want the row to span “2” columns. Now, since each <td> tag defines a column, and we told the first <td> to span both columns, we do not need the second <td> tag. I drew a line through it for a totally awesome effect, but you will have to remove that line of code completely.
<table border = "0"> <tbody> <tr> <td>Row 1 Column 1</td> <td>Row 1 Column 2</td> </tr> <tr> <td colspan="2">Row 2 Column 1 and 2 Merged</td><td>Row 2 Column 2</td></tr> </tbody> </table>
Once you remove it, your finished code should resemble the code below.
<table border = "0"> <tbody> <tr> <td>Row 1 Column 1</td> <td>Row 1 Column 2</td> </tr> <tr> <td colspan="2">Row 2 Column 1 and 2 Merged</td> </tr> </tbody> </table>
Here is what the table code above will look like parsed by the web browser.
Row 1 Column 1 | Row 1 Column 2 |
Row 2 Column 1 and 2 Merged |
How To Use It
Table 1 shows the basic two row and two column table. We use the table to place two 125 x 125 pictures in each cell of the first row leaving row 2 columns 1 and 2 for additional pictures.
Table 1
Row 2 Column 1 | Row 2 Column 2 |
Next, we decide to add a 250 x 125 picture in row 2. If we simple add it to one of the cells, that cell not only stretches to accomodate this larger picture, but also stretches the corresponding column in row 1. The unpleasant result is shown in Table 2.
Table 2
Row 2 Column 2 |
By spanning the row across two columns, we create a single cell that has the width of two columns as shown in Table 3.
Table 3
Maybe you want three 125 x 125 pictures in row 1, and two pictures in row 2 with one being 250 x 125 and the other 125 x 125? That can be easily done by applying the same colspan principles. But rather than give you the code, I will let you try to figure it out. Hint: you can view the source code of this webpage.
Table 4
Maria @ Craft Crazy Mom says
I just pinned this! I did most of the html on my blog and I have yet to make a table. Thanks SO SO SO much for sharing! Newest follower via the blog hop š
Monica says
Hi,
I am a new GFC follower. I found you on a blog hop. I would love for you to stop by my site and follow me as well. Also check out our giveaway for a $170 Technogel Pillow if you are interested. Thanks
http://www.chunkyandmonkeymd.com
Sherry says
Thanks so much for hosting this blog hop party!
Tiffany @ No Ordinary Homestead says
Very useful post. Tables can really make things look and flow so much better. Although I don't use it for many things, tables to throw stuff up on my blog is a very good reason to keep Dreamweaver installed on my computer. Then I don't have to remember to open and close all the bits & pieces of the table. There's some great free HTML editors out there as well, like nvu, which can help with the more complicated tables.
Just found your blog via 36th Ave & the blog hop š
Kyra says
Thanks for trying to help the technically challenged like me!! This is great! However, can I trade you dinner for technical support š Ha – I'll try to figure this out- I love it.
New follower via tip junkie!
kyra @caramelpotatoes.com
How to Nest for Less says
Holy smackers girl! I need to take some HTML classes š
Alisha Goinggfree says
Thank You so much for this tut!! You are awesome!!!
Alisha
Marriage from Scratch says
Very informative! thanks!
Iād love if you would come link this up at From Scratch Friday!
~Christina
http://www.marriagefromscratch.blogspot.com
AmieAnn says
You and your hubby are html rock stars! Thanks so much for sharing with the Pink Hippo Party.. can't wait to see what you share next!
cathy@my1929charmer says
You guys sure know your stuff, except I don't think I do. Very informative, but it's like chemistry, just kinds of freaks me out. I so do appreciate you trying to "enlighted". Thanks for sharing your creative inspiration at Sunday's Best Par.tay!
Emily @ 52 Mantels says
Awesomeness!! I've been meaning to try this out, but haven't gotten around to it yet. Why oh why is my to-do list so long?? But, I will be doing this asap! š
Thanks so much for linking up last Thursday!! You rock!
Polkadot-pretties says
Fabulous project!!!
Thank you for linking up, hope you will stop by my blog today and link up another great project…
Claire xox
http://polkadot-pretties.blogspot.com/