You can do this with colspan
and defining a width
according to the number of columns divided 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>
The logic is a little complicated, but it’s based on the values of colspan
summed and in the number of columns. Note that in the row where there are more columns, I do not specify colspan
in the first and last, only in the middle. The sum of the colspan
+ number of columns without colspan
of each row must be equal. In the first example, see that adding the value of colspan="3"
in the first row + 2 columns without colspan
, gives 5. In the second line also gives 5 summing the values of the colspan
. 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>
Note 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.
That is exactly what I wanted, thank you very much for the reply, I understood perfectly
– Droopy