Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can HTML table have variable number of cells on rows?

Tags:

Or should the total amount of cells equal to columns * rows?

A table with different amount of cells on different rows seems to pass the W3 Validator.

like image 974
randomguy Avatar asked Aug 14 '10 19:08

randomguy


People also ask

Is it possible to create table rows with different number of columns in HTML?

Spanning Multiple Rows and Columns Spanning allow you to extend table rows and columns across multiple other rows and columns. Normally, a table cell cannot pass over into the space below or above another table cell. But, you can use the rowspan or colspan attributes to span multiple rows or columns in a table.

How do I make a table with different number of rows in each column?

The Solution: Select the first part of the text to which you want to apply a different number of columns, choose Format » Columns, specify the number of columns, make sure that "Selected text" rather than "Whole document" is selected in the "Apply to" drop-down list, and click the OK button.


2 Answers

That does not violate the definition. But you should use the colspan attribute to expand the column to the whole row:

<table>
  <tr>
    <td>Row with</td>
    <td>2 cols</td>
  </tr>
  <tr>
    <td colspan="2">Row with only one col</td>
  </tr>
</table>

That will also help if you have borders around the cells.

You can even have tables with a column that expands to two rows:

<table>
  <tr>
    <td rowspan="2">First column in row 1 and row 2</td>
    <td>Second column in row 1</td>
  </tr>
  <tr>
    <td>second column in row 2</td>
  </tr>
</table>
like image 167
2ndkauboy Avatar answered Sep 30 '22 03:09

2ndkauboy


You can use colspan, but the sum including the colspan value(s) should be equal for the table to render properly.

<table>
  <tr>
     <td colspan="2">blah</td>
  </tr>
  <tr>
     <td>blah</td>
     <td>boo</td>
  </tr>
</table>

The first row has one cell but it spans 2 cells because of the colspan, the second row has two cells and this is perfectly valid.

like image 24
meder omuraliev Avatar answered Sep 30 '22 05:09

meder omuraliev