00 Votes

HTML: Table - Merge Cells

Question by MyDVDs | 2012-08-15 at 18:47

I have a table with 2 rows and 2 columns, a total of 4 cells:

<table>
  <tr>
    <td>Cell 1</td>
    <td>Cell 2</td>
  </tr>
  <tr>
    <td>Cell 3</td>
    <td>Cell 4</td>
  </tr>
</table>

Now, I want to connect the two upper cells (that is Cell 1 and Cell 2), because there will be a long sentence over the entire width of the table. Is this possible somehow?

ReplyPositiveNegative
2Best Answer2 Votes

The magic word is colspan. With colspan, you define the number of cells through which a cell should be extended in the right.

In your example that would be:

<table>
  <tr>
    <td colspan="2">Long Column</td>
  </tr>
  <tr>
    <td>Cell 3</td>
    <td>Cell 4</td>
  </tr>
</table>

With this, Cell 1 and Cell 2 are connected to a long cell over two cells.

If you want to join cells under each other together, it works with rowspan. Simply paste it into the first cell like it is also feasible in the example above.
Last update on 2020-09-03 | Created on 2012-08-18

ReplyPositive Negative
Reply

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.