作者:air12345 | 来源:互联网 | 2023-05-16 19:35
The Issue
I'm currently in a pickle. I need to group selectors inside of a Sass loop. I've tried many different ways to go about doing this such as:
我现在正在泡菜。我需要在Sass循环中对选择器进行分组。我已尝试过许多不同的方法来做到这一点,例如:
body {
$store: null;
@for $i from 1 through 10 {
$store: append($store, ".offset-by-#{$i}", comma);
}
// produces content: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10;
@each $j in $store {
$store: unquote($j);
}
// produces .offset-by-10
}
What I'm trying to accomplish using pure Sass (no Ruby) is the following:
我想用纯Sass(没有Ruby)来完成的是以下内容:
.offset-by-1,
.offset-by-2,
.offset-by-3,
...
.offset-by-10 { foo: bar; }
If you are a Sass god then please give me an idea of what to do here. If this is an inherent limitation of the meta-language then let me know about that too!
如果你是萨斯神,那么请告诉我这里要做什么。如果这是元语言的固有限制,那么请告诉我这一点!
Considerations
I can't use anything other than a mixin to accomplish this because functions are expected to be used on a property value. Mixins, on the other hand allow the production of entire blocks of code.
我不能使用mixin之外的任何东西来实现这一点,因为函数应该用在属性值上。另一方面,Mixins允许生成整个代码块。
2 个解决方案