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

查看:13
本文介绍了使用第 n 个子值作为 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 + 1}) {
     background: rgb($i, $i, $i);
  }
}

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

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