Make a <td> span the entire row in a table

HtmlHtml Table

Html Problem Overview


I'm not new to HTML but haven't touched it for some good time and I've encountered an annoying problem.

I have a table with two rows.
I want the first row to have one column - means that it will span the entire row, and I want the second row to have three columns, each one 33.3% of the row's width.

I have this code for the table :

<table width="900px" border="0" cellspacing="0" cellpadding="0">
    <tr>
        <td align="center">check</td>
    </tr>
    <tr>
        <td align="center">check</td>
        <td align="center">check</td>
        <td align="center">check</td>
    </tr>
</table>

But what happens is weird, the first row has one column with the same size as the second row's first column, and whenever I change one of them, it changes the other one too.

If I give the first row's <td> the width value of 500px lets say, it sets the second row's first <td> to the same size.

What am I doing wrong ?

Html Solutions


Solution 1 - Html

You should use the colspan attribute on the first row's td.
Colspan="3" will set the cell to flow over 3 columns.

<table width="900px" border="0" cellspacing="0" cellpadding="0">
    <tr>
        <td align="center" colspan="3">check</td>
    </tr>
    <tr>
        <td align="center">check</td>
        <td align="center">check</td>
        <td align="center">check</td>
    </tr>
</table>

Solution 2 - Html

You want to use the colspan attribute like this:

 <table width="900px" border="0" cellspacing="0" cellpadding="0">
    <tr>
        <td align="center" colspan="3">check</td>
    </tr>
    <tr>
        <td align="center" >check</td>
       <td align="center">check</td>
       <td align="center">check</td>
    </tr>
</table>

Solution 3 - Html

You can use colspan

<td align="center" colspan="3">check</td>

http://www.w3schools.com/tags/att_td_colspan.asp

Solution 4 - Html

If you're using JSX (React) it should be written like this. The s in colspan is capitalized and the value is a number instead of a string.

<td colSpan={3}>Text</td>

Solution 5 - Html

Using colspan like this:

    <tr>
        <td align="center" colspan="3">check</td>
    </tr>

By colspan you merge the following cells in a row to one. If you use 2 in your sample you get one cell with a width of the first two columns and the third is as the third in the rest of the table.

Solution 6 - Html

alter the first row with the below

<tr>
    <td colspan="3" align="center">check</td>
</tr>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNadav PeledView Question on Stackoverflow
Solution 1 - Htmlcypher75View Answer on Stackoverflow
Solution 2 - HtmlWidorView Answer on Stackoverflow
Solution 3 - Htmlarmen.shimoonView Answer on Stackoverflow
Solution 4 - HtmlNeluView Answer on Stackoverflow
Solution 5 - HtmlChristianView Answer on Stackoverflow
Solution 6 - HtmlAruView Answer on Stackoverflow