0

I have a nested table but for some reason, the CSS selector seems broken after the nested table.

.yellow {
  background-color: yellow;
}
<table>
  <tr class="yellow">
    <td>1</td>
    <td>2</td>
    <td>3</td>
    <td>
      <table>
        <tr>
          <td>4</td>
        </tr>
      </table>
      <td/>
  </tr>
  <tr>
    <table>
      <tr class="yellow">
        <td>
          5
        </td>
      </tr>
    </table>
  </tr>
  <tr class="yellow">
    <td>6</td>
    <td>7</td>
    <td>8</td>
  </tr>
</table>

https://jsbin.com/zuxagenoba/edit?html,css,output

2
  • 2
    What do you mean by "broken"? nimb.ws/w4tKul Commented Jan 22, 2021 at 18:03
  • 1
    Note that your HTML is invalid. You have a <table> as a child of a <tr> Commented Jan 22, 2021 at 18:05

1 Answer 1

1

the issue is that your nested table (the one which contains 5) is a direct child of tr element and you have a missing td element. Wrapping that table with and fixes the issue. See code snippet below

.yellow {
  background-color: yellow;
}
<table>
  <tr class="yellow">
    <td>1</td>
    <td>2</td>
    <td>3</td>
    <td>
      <table>
        <tr>
          <td>4</td>
        </tr>
      </table>
      <td/>
  </tr>
  <tr>
    <td>
    <table>
      <tr class="yellow">
        <td>
          5
        </td>
      </tr>
    </table>
  </td>
  </tr>
  <tr class="yellow">
    <td>6</td>
    <td>7</td>
    <td>8</td>
  </tr>
</table>

Sign up to request clarification or add additional context in comments.

1 Comment

oh, I see the nested table needs to be inside a td then, thanks a lot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.