3

我知道选择器:not(),但它不起作用,比如tr:not(tr:first-child):hover. 我想为其他trs 设置样式,但不是第一个,因为它包含标题。我怎么能不使用idor来做到这一点class

4

4 回答 4

3

您只能在 中使用简单的选择器:not()尝试

tr:not(:first-child)

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

于 2013-10-09T01:39:23.883 回答
2

另一种选择是使用专门表示表格中标题单元格的th元素。

例子

<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>
于 2013-10-11T22:02:23.540 回答
1

使用相邻的兄弟组合器。作为奖励,它的支持范围比:not()

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

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

于 2013-10-09T01:37:20.103 回答
0

将您的标题放在 a中,然后使用<thead>您的可样式行:<tbody>

tbody tr:hover { background: red }

内容是什么并不重要。

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

于 2013-10-12T05:46:34.257 回答