You can do this with colspan
and setting width
according to the number of columns dividing by 100%. For example: 3 columns = 33.3%, 4 columns = 25% and so on ...
Example of 2 rows of 4 x 3 columns:
<table width="100%" border="1">
<tr>
<td width="25%"> ola </td>
<td width="25%" colspan="3"> ola </td>
<td width="25%" colspan="2"> ola </td>
<td width="25%"> ola </td>
</tr>
<tr>
<td width="33.3%" colspan="2"> ola </td>
<td width="33.3%" colspan="3"> ola </td>
<td width="33.3%" colspan="2"> ola </td>
</tr>
</table>
3x2:
<table width="100%" border="1">
<tr>
<td width="33.3%"> ola </td>
<td width="33.3%" colspan="3"> ola </td>
<td width="33.3%"> ola </td>
</tr>
<tr>
<td width="50%" colspan="3"> ola </td>
<td width="50%" colspan="2"> ola </td>
</tr>
</table>
5x4:
<table width="100%" border="1">
<tr>
<td width="20%"> ola </td>
<td width="20%" colspan="4"> ola </td>
<td width="20%" colspan="3"> ola </td>
<td width="20%" colspan="4"> ola </td>
<td width="20%"> ola </td>
</tr>
<tr>
<td width="25%" colspan="2"> ola </td>
<td width="25%" colspan="5"> ola </td>
<td width="25%" colspan="4"> ola </td>
<td width="25%" colspan="2"> ola </td>
</tr>
</table>
Logic is a bit tricky, but it is based on the values of the% added% and the number of columns. See that in the row where you have more columns, I do not specify colspan
in the first and last, only in the middle. The sum of colspan
+ number of columns with% w / o of% of each line must be equal. In the first example, you see that by adding the value of colspan
in the first row + 2 columns without colspan
, gives 5. In the second line also gives 5 by adding the values of colspan="3"
. These numbers go up as more columns are added.
See another example with 5x3:
<table width="100%" border="1">
<tr>
<td width="20%"> ola </td>
<td width="20%" colspan="4"> ola </td>
<td width="20%" colspan="3"> ola </td>
<td width="20%" colspan="4"> ola </td>
<td width="20%"> ola </td>
</tr>
<tr>
<td width="33.3%" colspan="3"> ola </td>
<td width="33.3%" colspan="7"> ola </td>
<td width="33.3%" colspan="3"> ola </td>
</tr>
</table>
See that the logic follows the same: adding the values of the first line, 1 + 4 + 3 + 4 + 1 = 13. In the second line also: 3 + 7 + 3 = 13.