【发布时间】:2012-11-09 01:31:45
【问题描述】:
我正在尝试选择某个类的行中的所有元素,但该类的最后一行除外。我一直在尝试找出正确的语法来这样做,但我就是想不通。
这是我认为可以完成这项工作的 CSS:
tr.ListRow:not(:last-of-type) td {
padding: 14px;
border-bottom-color: #768ca5;
border-bottom-width: 1px;
border-bottom-style: solid;
}
这是 HTML,因此您可以了解我要做什么。
<tbody>
<tr class="Row ListRow">..........</tr> <!-- CSS applied to <td> tags within -->
<tr class="Graph">..........</tr>
<tr class="AltRow ListRow">........</tr> <!-- CSS applied to <td> tags within -->
<tr class="Graph">..........</tr>
<tr class="Row ListRow">..........</tr> <!-- CSS applied to <td> tags within -->
<tr class="Graph">..........</tr>
.
.
.
.
<tr class="AltRow ListRow">........</tr> <!-- CSS NOT applied to this last row of class ListRow -->
<tr class="Graph">..........</tr>
</tbody>
编辑:我最终选择了一条 javascript 路线,我在下面回答了该路线。
【问题讨论】:
-
.xyz:last-child不会获取类为xyz的所有元素,然后找到该集合中的最后一个元素,反之亦然,它将抓取最后一个子元素,然后如果它有一个类xyz将匹配。 :last-of-type、nth-child 和其他所有内容也是如此。所以没有办法找到某个类的最后一个元素。
标签: html css css-selectors