我在使用SASS @extend
我有以下代码http://codepen.io/anon/pen/AgCnF?editors=110
<ul>
<li>one</li>
<li>two</li>
<li>three</li>
<li>four</li>
</ul>
$link-different: 1, 2
li
@if $link-different != 0
%different-background
background: #000
@each $different in $link-different
&:nth-child(#{$different})
@extend %different-background !optional
@else
但是它在CSS选择器路径上输出了两个li
元素
li li:nth-child(1), li li:nth-child(2) {
background: black;
}
如何输出?
li:nth-child(1), li:nth-child(2) {
background: black;
}
答案 0 :(得分:2)
$link-different: 1, 2
%different-background
background: #000
li
@if $link-different != 0
@each $different in $link-different
&:nth-child(#{$different})
@extend %different-background !optional
@else
输出
li:nth-child(1), li:nth-child(2) {
background: black;
}