2

I don't have much experience with html, but I tried to make a simple table and I get extra cells in it, I don't know why. Here is the code:

<table border="1">
    <tr>
        <td colspan="5"> hi <td>
        <td colspan="3"> hi <td>
    </tr>
    <tr>
        <td colspan="3"> hi <td>
        <td colspan="5"> hi <td>
    </tr>
</table>

I expect this to have two rows with 2 cells in each, in first row first cell is bigger, and in second row second cell is bigger. But for some reason I get 4 cells in each row, like this:

.

2
  • Why are you using colspan=5 + 3 in a table that has only two columns? If you get rid of that, it'll work.
    – Pekka
    Commented Feb 9, 2012 at 15:09
  • Why are you having those colspans there if you are looking to have just 2 columns in both rows? Removing the colspans will remove the extra cells as well.
    – techfoobar
    Commented Feb 9, 2012 at 15:09

4 Answers 4

6

You didn't terminate your <td>.... You need a </td> at the end.

Working Fiddle

http://jsfiddle.net/GFdP6/3/

<table border="1">
    <tr>
        <td colspan="5"> hi </td>
        <td colspan="3"> hi </td>
    </tr>
    <tr>
        <td colspan="3"> hi </td>
        <td colspan="5"> hi </td>
    </tr>
</table>

Furthermore

If you want it to look like you'd expect, you will have to set some widths on your td's like I did in the fiddle.

1
  • +1 - Took me a few seconds to realise what you'd changed. Sometimes it's really hard to spot the obvious, nice catch :P
    – Hecksa
    Commented Feb 9, 2012 at 15:10
1

You have used TD Start Tags when you want TD End Tags. So you have 4 TD elements in each row instead of 2. (Note that the end tag for TD is optional so this is valid).

0

It's a typo... The closing TD tags are missing.

<table border="1"> 
    <tr> 
        <td colspan="5"> hi --> close your tags here --> </td>
        <td colspan="3"> hi </td> 
    </tr> 
    <tr> 
        <td colspan="3"> hi </td> 
        <td colspan="5"> hi </td> 
    </tr> 
</table> 
0

Missing closing tags for <td>.

<table border="1"> 
    <tr> 
        <td colspan="5"> hi </td> 
        <td colspan="3"> hi </td> 
    </tr> 
    <tr> 
        <td colspan="3"> hi </td> 
        <td colspan="5"> hi </td> 
    </tr> 
</table> 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.