我不知道这是否可能,但社会科学院是否有办法确定某一类别是属于哪一类的?
如果我有:
<ul>
<li></li>
<li></li>
<li class="Selected"></li>
<li></li>
<li></li>
</ul>我正在尝试获取一个混合器,以便根据“选中”类的位置切换CSS属性。所以,就像:
ul li { background: url(@include(mixin)); }
$Names:("../Images/One.png","../Images/Two.png","../Images/Three.png","../Images/Four.png","../Images/Five.png",)
@include mixin($Names){
@each $liindex in $Names{
$i: index($Names, $liindex );
if(/* see if this li has class Selected */){
/* change property here?
}
}
}发布于 2022-03-01 17:25:26
这应该可以用nth-of-type完成。就像这样:
@mixin bg-mixin($Names){
@each $bg-url in $Names{
$i: index($Names, $bg-url );
&:nth-of-type(#{$i}).Selected { background: url($bg-url); }
}
}像这样使用:
ul li {
@include bg-mixin($Names);
}结果是
ul li:nth-of-type(1).Selected {
background: url("../Images/One.png");
}
ul li:nth-of-type(2).Selected {
background: url("../Images/Two.png");
}
ul li:nth-of-type(3).Selected {
background: url("../Images/Three.png");
}
ul li:nth-of-type(4).Selected {
background: url("../Images/Four.png");
}
ul li:nth-of-type(5).Selected {
background: url("../Images/Five.png");
}https://stackoverflow.com/questions/71300453
复制相似问题