Make a <td> span the entire row in a table
HtmlHtml TableHtml 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>
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>