Spec-Zone.ru › Sass

@for

Правило @for, написанное @for <variable> from <expression> to <expression> { ... } или @for <variable> from <expression> through <expression> { ... }, считает вверх или вниз от одного числа (результата первого выражения) до другого (результата второго) и вычисляет блок для каждого числа между ними. Каждое число по пути присваивается заданному имени переменной. Если используется to, конечное число исключается; если используется through, оно включается.

$base-color: #036;

@for $i from 1 through 3 {
  ul:nth-child(3n + #{$i}) {
    background-color: lighten($base-color, $i * 5%);
  }
}
// SASS
$base-color: #036

@for $i from 1 through 3
  ul:nth-child(3n + #{$i})
    background-color: lighten($base-color, $i * 5%)
/* CSS */
ul:nth-child(3n+1) {
  background-color: rgb(0, 63.75, 127.5);
}

ul:nth-child(3n+2) {
  background-color: rgb(0, 76.5, 153);
}

ul:nth-child(3n+3) {
  background-color: rgb(0, 89.25, 178.5);
}

© 2006–2025 the Sass team, and numerous contributors
Licensed under the MIT License.
https://sass-lang.com/documentation/at-rules/control/for

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API