如何在sass中使用循环生成多个mixin(mixin lib)

Lia*_*ang 5 sass

我想保持我的 sass 代码简短。

代替

@mixin tg($font-size,$line-height) {
  something related to font-size and line-height
}

@mixin h1 {
  @include tg 
}

@mixin h2 {
  @include tg 
}

....
Run Code Online (Sandbox Code Playgroud)

如何使用循环创建@mixin lib?

$typography-list: h1, h2......
@mixin tg($font-size,$line-height) {
  something related to font-size and line-height
}


@each $typography in $typography-list {
  create @mixin {
    @include tg()
  }
}
Run Code Online (Sandbox Code Playgroud)

如果是这样,最好的方法是什么?

Har*_*til 1

本质上,您指的是SCSS生产SCSS。这称为元编程。在 中这是不可能的SASS。除非 SASS 发明了某种技术或者你有另一种可以编译为SCSS.

简而言之,目前你还不能这样做。