简体   繁体   中英

Why does this html table get extra cells?

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:

.

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.

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).

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> 

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> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM