Seb*_*lia 6 css loops sass mixins modulo
我想编写一个sass mixin,从1到100每5步输出一个特定的类.但我不能让modulo运算符以某种方式工作.根本没有创建类.
这是我的代码
@mixin flex_percentage($className) {
@for $i from 1 through 100 {
@if $i % 5 != 0 {
.#{$className}#{$i} {
width: $i * 1%;
}
}
}
}
@include flex_percentage(p);
Run Code Online (Sandbox Code Playgroud)
我也尝试了$i mod(5)
但是它输出了所有100个类.
我希望有一个类似的输出
.p5 {
width: 5%;
}
.p10 {
width: 10%;
}
.p15 {
width: 15%;
}
Run Code Online (Sandbox Code Playgroud)
Kat*_*ieK 12
本@if $i % 5 != 0 {
应该是这样的:
@if $i % 5 == 0 {
Run Code Online (Sandbox Code Playgroud)
所不同的是之间!=
和==
中if
条款.您的原始代码实际上是输出除了 5的倍数之外的每个类.如果我们将其更改为==
,则只输出那些5的倍数的类.
实例:http://sassmeister.com/gist/7550271