For loop 如何覆盖循环的SCSS中的整数步数(从*到*)

For loop 如何覆盖循环的SCSS中的整数步数(从*到*),for-loop,sass,increment,For Loop,Sass,Increment,有办法做到这一点吗 SCSS:(sudo代码) CSS输出: .bottom-0 { bottom: 0em; } .bottom-05 { bottom: 0.5em; } .bottom-1 { bottom: 1em; } .bottom-15 { bottom: 1.5em; } .bottom-2 { bottom: 2em; } @for $i from 0 through 10 { // double 10 if you want

有办法做到这一点吗

SCSS:(sudo代码)

CSS输出:

.bottom-0 {
    bottom: 0em;
}

.bottom-05 {
    bottom: 0.5em;
}

.bottom-1 {
    bottom: 1em;
}

.bottom-15 {
    bottom: 1.5em;
}

.bottom-2 {
    bottom: 2em;
}
@for $i from 0 through 10 { // double 10 if you want to go to ten!

  $iletter: $i*10/2;
  @if $iletter < 10 {
    $iletter: "0" + $iletter
  }

  $i: $i/2;
  .bottom-#{$iletter} {
    bottom: 1em * $i;
  }
}
.bottom-00 {
  bottom: 0em;
}

.bottom-05 {
  bottom: 0.5em;
}

.bottom-10 {
  bottom: 1em;
}

.bottom-15 {
  bottom: 1.5em;
}

.bottom-20 {
  bottom: 2em;
}

.bottom-25 {
  bottom: 2.5em;
}

.bottom-30 {
  bottom: 3em;
}

.bottom-35 {
  bottom: 3.5em;
}

.bottom-40 {
  bottom: 4em;
}

.bottom-45 {
  bottom: 4.5em;
}

.bottom-50 {
  bottom: 5em;
}

我基本上希望for循环以0.5的增量迭代到10,输出类似于上面css块中的内容,而不在类名中包含.5,因为它会将其视为嵌套类。

完成了!有点老套,但它很管用:

SCSS:

.bottom-0 {
    bottom: 0em;
}

.bottom-05 {
    bottom: 0.5em;
}

.bottom-1 {
    bottom: 1em;
}

.bottom-15 {
    bottom: 1.5em;
}

.bottom-2 {
    bottom: 2em;
}
@for $i from 0 through 10 { // double 10 if you want to go to ten!

  $iletter: $i*10/2;
  @if $iletter < 10 {
    $iletter: "0" + $iletter
  }

  $i: $i/2;
  .bottom-#{$iletter} {
    bottom: 1em * $i;
  }
}
.bottom-00 {
  bottom: 0em;
}

.bottom-05 {
  bottom: 0.5em;
}

.bottom-10 {
  bottom: 1em;
}

.bottom-15 {
  bottom: 1.5em;
}

.bottom-20 {
  bottom: 2em;
}

.bottom-25 {
  bottom: 2.5em;
}

.bottom-30 {
  bottom: 3em;
}

.bottom-35 {
  bottom: 3.5em;
}

.bottom-40 {
  bottom: 4em;
}

.bottom-45 {
  bottom: 4.5em;
}

.bottom-50 {
  bottom: 5em;
}

@cimmanon-这与您将其标记为重复的问题无关。请重新考虑。我唯一会重新考虑的是我对复制品的选择@cimmanon-这些是带有整数的步骤。很接近,但肯定没有雪茄?!我说的是半个数字,在类名中安全地表示,而不使用。(出于显而易见的原因,哈哈!)真的吗?你会争辩说,
$i*.5
$i/2
不同于
$i+2
?呃,cimmanon,这很有侵略性,任何想象都不能完全复制