1

can somebody explain that how does this colspan and rowspan system works, i have made this with rowspan="4" but it looks like it is actually 3 and not 4 i mean the result, and why are '55577855' and 'ikä' are on right side, shoudn't those two be under 'henkilöstöt' ? i have tried many times.

<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
    border: 1px solid black;
    border-collapse: collapse;
}
th, td {
    padding: 5px;
    text-align: left;    
}
</style>
</head>
<body>


<table >
 
<tr>
  <th rowspan="4">Henkilöstöt</th>
  <th colspan="3">koulutus</th>
</tr>
<tr>
 <th rowspan="3">Muu</th>
 <th rowspan="3">Ammattiiiii</th>
 <th rowspan="3">korkeakoulu</th>
</tr>
  
   <tr>
    <th >55577855</th>
  </tr>
   <tr>
    <th>ikä</th>   

  </tr>

</table>
   

  

</body>
</html>
Johannes
  • 64,305
  • 18
  • 73
  • 130
waleedd32
  • 473
  • 2
  • 9
  • 23
  • The [HTML specification has examples of how these attributes work](https://html.spec.whatwg.org/multipage/tables.html#table-examples)... – Heretic Monkey May 23 '18 at 18:42
  • among other things, you don't have any regular table cells (`td`), but only header cells (`th`) , which for sure isn't valid HTML... – Johannes May 23 '18 at 18:52
  • @Johannes Could you correct that so i could learn from it, it should look same but '55577855 ' and 'ikä' should be under 'henkilöstöt' – waleedd32 May 23 '18 at 18:54

4 Answers4

1

The rowspan and colspan are attributes of tag how could you use that with tr and th

You should try to use the colspan and rowspan with td

Shubham Kumar
  • 295
  • 3
  • 13
1

maybe, this will help you..

    <table border ="1">

<tr>
  <th>Henkilöstöt</th>
  <th>koulutus</th>
</tr>

  <tr>
<td >Muu</th>
 <td >Ammattiiiii</td>
 <td >korkeakoulu</td>
</tr>
   <tr>
    <td>55577855</td>
  </tr>
   <tr>
    <td>ikä</td>   


  </tr>



</table>
Shubham Kumar
  • 295
  • 3
  • 13
1

It's hard to guess what you really want (you should have supplied a graphic of he desired output), but if you want the last two table rows to go under the other ones, you have to insert two empty rows to make up for the rowspans in the first row.

<!DOCTYPE html>
<html>

<head>
  <style>
    table {
      border-collapse: collapse;
    }
    
    th,
    td {
      border: 1px solid black;
      padding: 5px;
      text-align: left;
    }
  </style>
</head>

<body>


  <table>

    <tr>
      <th rowspan="4">Henkilöstöt</th>
      <th colspan="3">koulutus</th>
    </tr>
    <tr>
      <td rowspan="3">Muu</td>
      <td rowspan="3">Ammattiiiii</td>
      <td rowspan="3">korkeakoulu</td>
    </tr>
    <tr>
    </tr>
    <tr>
    </tr>

    <tr>
      <td colspan="4">55577855</td>
    </tr>
    <tr>
      <td colspan="4">ikä</td>
    </tr>

  </table>




</body>

</html>
Johannes
  • 64,305
  • 18
  • 73
  • 130
0

Rowspan makes an element extend down into the next row.

You have four rows:

  • Henkilöstöt, koulutus
  • Muu, Ammattiiiii, korkeakoulu
  • 55577855
  • ikä

When you tell the second row to extend three rows down, you aren't telling it to become three times as large, you're telling it to appear on the same row as the third and fourth row. The third and fourth row keep their data cells and push them to the first available location.

You should either stick two empty rows after the korkeakoulu row, or you should reduce the values of all of your rowspans by 2.

EDIT

<tr>
  <th rowspan="2">Henkilöstöt</th>
  <th colspan="3">koulutus</th></tr>
<tr>
 <td>Muu</td>
 <td>Ammattiiiii</td>
 <td>korkeakoulu</td>
</tr>

<tr>
<td >55577855</td>
</tr>
<tr>
<td>ikä</td>   

</tr>

</table>

Or you can use:

<table>
<tr>
  <th rowspan="4">Henkilöstöt</th>
  <th colspan="3">koulutus</th>
</tr>
<tr>
 <th rowspan="3">Muu</th>
 <th rowspan="3">Ammattiiiii</th>
 <th rowspan="3">korkeakoulu</th>
</tr>
<tr></tr>
<tr></tr>
   <tr>
    <th >55577855</th>
  </tr>
   <tr>
    <th>ikä</th>   

  </tr>

</table>