CSS: Selecting table's without the s of nested tables

后端 未结 3 836
礼貌的吻别
礼貌的吻别 2021-01-18 13:17

How do you select the td elemennts of a table, without the td\'s of the nested tables ?
I thought of the following selector: table > tbody &g

相关标签:
3条回答
  • 2021-01-18 13:59

    Easiest way is to add an id or class to that outermost table, an then use that in your selector:

    table#id > tbody > tr > td
    
    0 讨论(0)
  • 2021-01-18 14:05

    Honestly, I don't think what you're trying to achieve is possible. What you might do is overwrite any unwanted styles to the nested table cells. So if you apply a red background to a cell, and that cell has nested cells, you need to overwrite the nested cells with the original background color.

    0 讨论(0)
  • 2021-01-18 14:15

    So you have this?

    <table id="outer">
       <tbody>
          <tr>
             <td>
                <table id="anotherTable">
                ...
                </table>
             <td>
          <tr>
       </tbody>
    </table>
    

    And you want to only select td's in the root table.

    #outer>tbody>tr>td
    

    Just like you entered in your question (direct child selectors).

    0 讨论(0)
提交回复
热议问题