--- id: 587d7dbf367417b2b2512bbb title: Apply a Style Until a Condition is Met with @while challengeType: 0 forumTopicId: 301454 localeTitle: 使用 @while 当条件满足时样式生效 --- ## Description
Sass 中的@while指令与 JavaScript 中的while类似。只要满足条件,它就会一直创建 CSS 代码。 @for挑战提供了一个创建简单网格系统的示例。这也适用于@while。 ```scss $x: 1; @while $x < 13 { .col-#{$x} { width: 100%/12 * $x;} $x: $x + 1; } ``` 首先,定义变量$x并将其设置为 1。接下来,使用@while指令,当$x小于 13 时创建网格系统 。 在设置width的 CSS 规则后,$x增加 1 以避免无限循环。
## Instructions
使用@while创建一系列具有不同font-sizes的 class。 从text-1text-10应该有 10 个不同的 class。然后将font-size设置为 15px 乘以当前索引号。注意不要写成死循环!
## Tests
```yml tests: - text: 你的代码应使用@while指令。 testString: assert(code.match(/@while /g)); - text: 你的代码应将索引变量设置为 1 才能启动。 testString: assert(code.match(/\$.*:\s*?1;/gi)); - text: 你的代码应该递增计数器变量。 testString: assert(code.match(/\$(.*)\s*?:\s*\$\1\s*\+\s*1\s*;/gi)); - text: .text-1class 的font-size应为 15px。 testString: assert($('.text-1').css('font-size') == '15px'); - text: .text-2class 的font-size应为 30px。 testString: assert($('.text-2').css('font-size') == '30px'); - text: .text-3class 的font-size应为 45px。 testString: assert($('.text-3').css('font-size') == '45px'); - text: .text-4class 的font-size应为 60px。 testString: assert($('.text-4').css('font-size') == '60px'); - text: .text-5class 的font-size应为 75px。 testString: assert($('.text-5').css('font-size') == '75px'); ```
## Challenge Seed
```html

Hello

Hello

Hello

Hello

Hello

```
## Solution
```html

Hello

Hello

Hello

Hello

Hello

```