@for
指令在循环中添加样式,非常类似于JavaScript中的for
循环。 @for
以两种方式使用:“ @for
”或“ @for
”。主要区别在于“从头到尾” 排除了结束号码,“从头到尾” 包括结束号码。这是一个开始到最后的例子: @for $ i从1到12 {
.col - #{$ i} {width:100%/ 12 * $ i; }
}
#{$i}
部分是将变量( i
)与文本组合成字符串的语法。当Sass文件转换为CSS时,它看起来像这样: .col-1 {这是创建网格布局的有效方法。现在,您有12个可用作CSS类的列宽选项。
宽度:8.33333%;
}
.col-2 {
宽度:16.66667%;
}
...
.col-12 {
宽度:100%;
}
@for
指令,它接受一个从1 到 6的变量$j
。它应该创建5个名为.text-1
到.text-5
,其中每个类的font-size
设置为10px乘以索引。 @for
指令。
testString: 'assert(code.match(/@for /g), "Your code should use the @for
directive.");'
- text: 您的.text-1
类的font-size
为10px。
testString: 'assert($(".text-1").css("font-size") == "10px", "Your .text-1
class should have a font-size
of 10px.");'
- text: 您的.text-2
类的font-size
为20px。
testString: 'assert($(".text-2").css("font-size") == "20px", "Your .text-2
class should have a font-size
of 20px.");'
- text: 您的.text-3
类的font-size
为30px。
testString: 'assert($(".text-3").css("font-size") == "30px", "Your .text-3
class should have a font-size
of 30px.");'
- text: 您的.text-4
类的font-size
为40px。
testString: 'assert($(".text-4").css("font-size") == "40px", "Your .text-4
class should have a font-size
of 40px.");'
- text: 您的.text-5
类的font-size
为50px。
testString: 'assert($(".text-5").css("font-size") == "50px", "Your .text-5
class should have a font-size
of 50px.");'
```
Hello
Hello
Hello
Hello
Hello
```