简体   繁体   English

CSS的变量类名

[英]variable class name for css

What I want is pretty simple: 我想要的很简单:

I want to be able to use classnames like: class-5, class-8, etc. 我希望能够使用类名,例如:class-5,class-8等。

In the css(scss), a variable should be able to pick up the numbers: 在css(scss)中,变量应该能够提取数字:

.class-x{
    font-size: rem-calc(x);
}

Is something like this at all possible(because that would be awesome)? 像这样完全有可能吗(因为那太棒了)?

I's possible if you have a limited number of x : 如果您的x数量有限,则有可能:

@for $i from 1 through 10 {
  .class-#{$i} {
    font-size: rem-calc($i);
  }
}

You could use a sass array of numbers you want to use, then loop through to build up the output for each index; 您可以使用一个简单的数字数组,然后循环遍历以建立每个索引的输出。

$numbers: 3, 5, 8, 9, 12, 15;
@each $i in $numbers {
  .class-#{$i} {
    font-size: rem-calc($i);
  }
}

DEMO DEMO

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM