除了第一个子元素外,样式化所有东西

4

我知道选择器:not(),但它不起作用,如tr:not(tr:first-child):hover。我想给其他的添加样式,但不想给第一个添加样式,因为它包含标题。我该怎么做,而不使用idclass

4个回答

4

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>

另外两个答案很聪明,但这个在语义上更准确。 - Jason Sperske
@thgaskell 这样做不容易使行的样式变得简单。 - stevemarvell
th { /* rules */ } 太难了吗? - thgaskell

1

0
将您的表头放在<thead>中,将可样式化的行放在<tbody>中,然后使用以下代码:
tbody tr:hover { background: red }

而它的内容是什么并不重要。

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接