runoops.com

Sass @for

语法:

@for <variable> from <expression> to <expression> { ... }
或
@for <variable> from <expression> through <expression> { ... }

如果使用 to,则排除最终数字;如果使用 THROUGH,则包含它。

SCSS


$base-color: #036;

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

编译为 CSS 结果:

CSS

ul:nth-child(3n + 1) {
  background-color: #004080;
}

ul:nth-child(3n + 2) {
  background-color: #004d99;
}

ul:nth-child(3n + 3) {
  background-color: #0059b3;
}

Captcha Code

0 笔记

分享笔记

Inline Feedbacks
View all notes