使用nth-child值作为SASS变量 [英] Use nth-child value as a SASS variable

查看:148
本文介绍了使用nth-child值作为SASS变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用 nth-child 值作为SASS变量?

Is there any way to use the nth-child value as a SASS variable ?

使用示例:

div:nth-child(n) {
    content: '#{$n}'
}





div:nth-child(n) {
    background: rgb(#{$n}, #{$n}, #{$n});
}


推荐答案

我不认为一种方式做到这一点。但您可以使用 @for 指令循环已知数量的元素:

I don't think there's a way to do exactly that. But you can use @for directive to loop through a known number of elements:

$elements: 15;
@for $i from 0 to $elements {
  div:nth-child(#{$i}) {
     background: rgb($i, $i, $i);
  }
}

这篇关于使用nth-child值作为SASS变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆