Search code examples
htmlhtml-tablemarkup

Why can't the browser render this table HTML properly?


I'm struggling with TABLE HTML. I have no idea why this table tag doesn't work properly in browser

<table border="1">
  <tbody>
    <tr>
      <td rowspan="2">1-1</td>
      <td rowspan="3">2-1</td>
    </tr>
    <tr>
      <td rowspan="2">1-2</td>
    </tr>
    <tr>
      <td rowspan="3">2-2</td>
    </tr>
    <tr>
      <td rowspan="2">1-3</td>
    </tr>
  </tbody>
</table>

The html above would be rendered like this

enter image description here

However the view I expected to see is like this

enter image description here

As I figured out, If I want to see what I want in browser, I should fix rowspans like this

<table border="1">
  <tbody>
    <tr>
      <td rowspan="1">1-1</td>
      <td rowspan="2">2-1</td>
    </tr>
    <tr>
      <td rowspan="2">1-2</td>
    </tr>
    <tr>
      <td rowspan="2">2-2</td>
    </tr>
    <tr>
      <td rowspan="1">1-3</td>
    </tr>
  </tbody>
</table>

But I'm really wondering what's different and why The browser (Chrome) doesn't render the first one properly and does the second one.


Solution

  • According to W3C there is no way to specify float value like 1.5 for rowspan but some tweaks like below may help.

    <table border="1">
      <tbody>
        <tr>
          <td rowspan="2">1-1</td>
        </tr>
         <tr>
          <td rowspan="2">1-2</td>
        </tr>
        <tr>
          <td rowspan="2">2-1</td>
        </tr>
        <tr>
          <td rowspan="3">2-2</td>
        </tr>
         <tr>
          <td rowspan="2">3-1</td>
        </tr>
      </tbody>
    </table>