Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate multiple mixins (mixin lib) with loop in sass

Tags:

sass

I would like to keep my sass code short.

instead of

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

@mixin h1 {
  @include tg 
}

@mixin h2 {
  @include tg 
}

....

How can i create a @mixin lib with loop?

$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()
  }
}

if so, what is the best way of doing it?

like image 849
Seeliang Avatar asked Sep 08 '16 00:09

Seeliang


1 Answers

In essence, you are referring to SCSS producing SCSS. This is called as meta-programming. It is not possible in SASS. Unless SASS invents some technique or you have another language that compiles to SCSS.

In short, currently, you cannot do that.

like image 94
Harshal Patil Avatar answered Sep 22 '22 17:09

Harshal Patil