Style every thing except first child

后端 未结 4 1986
眼角桃花
眼角桃花 2021-01-21 02:16

I know of the selector :not() but it doesn\'t work, like tr:not(tr:first-child):hover. I want to style the other trs but not the first one

相关标签:
4条回答
  • 2021-01-21 02:53

    You can only use simple selectors in :not(), try

    tr:not(:first-child)
    

    http://jsfiddle.net/mowglisanu/Sn7Uw/

    0 讨论(0)
  • 2021-01-21 03:06

    Another option would be to use the th element which is specifically represents the header cell in a table.

    Example

    <table>
      <thead>
        <tr>
          <th>Number</th>
          <th>element</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>4.1.1</td>
          <td>html</td>
        </tr>
        <tr>
          <td>4.2.1</td>
          <td>head</td>
        </tr>
      </tbody>
    </table>
    
    0 讨论(0)
  • 2021-01-21 03:07

    Use the adjacent sibling combinator. As a bonus, it's a bit more widely supported than :not()

    TR + TR { background-color: silver; }
    TR + TR:hover { background-color: green; }
    

    http://jsfiddle.net/ETYQN/2/

    0 讨论(0)
  • 2021-01-21 03:07

    Put your headers in a <thead> and your stylable rows in the <tbody> then use:

    tbody tr:hover { background: red }
    

    and it won't matter what the contents is.

    http://jsfiddle.net/stevemarvell/we4a6/

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