使用sass动态创建类

使用sass动态创建类,sass,Sass,我是否可以使用sass和循环来创建以下内容: .m-t-0 { margin-top: 0px !important; } .m-t-1 { margin-top: 1px !important; } .m-t-2 { margin-top: 2px !important; } .m-t-3 { margin-top: 3px !important; } .m-t-4 { margin-top: 4px !important; } .m-t-5

我是否可以使用sass和循环来创建以下内容:

.m-t-0 {
    margin-top: 0px !important;
}

.m-t-1 {
    margin-top: 1px !important;
}

.m-t-2 {
    margin-top: 2px !important;
}

.m-t-3 {
    margin-top: 3px !important;
}

.m-t-4 {
    margin-top: 4px !important;
}

.m-t-5 {
    margin-top: 5px !important;
}

.m-t-6 {
    margin-top: 6px !important;
}
这是您在Google上搜索“sass循环”时得到的第一个结果。以下是我们为参考页面的部分提供的内容:

@for $i from 1 through 4
  .#{$class-slug}-#{$i}
    width: 60px + $i
一旦适应了您提供的示例,您将得到以下结果:

@for $i from 0 through 6
  .m-t-#{$i}
    margin-top: 1px * $i !important
这是您在Google上搜索“sass循环”时得到的第一个结果。以下是我们为参考页面的部分提供的内容:

@for $i from 1 through 4
  .#{$class-slug}-#{$i}
    width: 60px + $i
一旦适应了您提供的示例,您将得到以下结果:

@for $i from 0 through 6
  .m-t-#{$i}
    margin-top: 1px * $i !important