【发布时间】:2017-11-25 20:48:40
【问题描述】:
我的 SCSS 如下所示:
.wrapper {
.part {
...
&.wheel {
... // code goes here
}
}
}
我的 html 看起来像这样:
<div class="wrapper">
<img src="..." class="part wheel"/>
<img src="..." class="part wheel"/>
</div>
如何使用 CSS 选择第一个和第二个 wheel?我想给他们不同的属性。
【问题讨论】:
-
看看
:nth-child选择器,但要小心,因为它是一个元素选择器(而不是类),所以如果中间有任何其他元素,它将不起作用 -
&:nth-of-type(1) { ... }和&:nth-of-type(2) { ... }