2017-06-22 43 views
-1

我SCSS的第二個看起來是這樣的:選擇第一和一流

.wrapper { 
    .part { 
     ... 
     &.wheel { 
      ... // code goes here 
     } 
    } 
} 

而且我的HTML看起來像這樣:

<div class="wrapper"> 
    <img src="..." class="part wheel"/> 
    <img src="..." class="part wheel"/> 
</div> 

如何選擇第一和使用CSS第二wheel?我想給他們不同的屬性。

+2

看看':第n-child'選擇,但要注意,因爲它是一個元素選擇器(而不是類),所以如果你(1){...}和'&:nth-​​of-type(2){...}'有一些其他的元素,它不會起作用 – Pete

+0

'&: –

回答

1
.wheel:nth-of-type(1){...} 
.wheel:nth-of-type(2){...} 

.wheel:nth-child(1){...} 
.wheel:nth-child(2){...} 
0

使用nth-of-type

.wrapper { 
    .part { 
     ... 
     &.wheel { 
      &:nth-of-type(1) { ... } 
      &:nth-of-type(2) { ... } 
     } 
    } 
}