如何在sass中使用循环生成多个mixin(mixin lib) [英] How to generate multiple mixins (mixin lib) with loop in sass
本文介绍了如何在sass中使用循环生成多个mixin(mixin lib)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想保持我的 sass 代码简短.
I would like to keep my sass code short.
代替
@mixin tg($font-size,$line-height) {
something related to font-size and line-height
}
@mixin h1 {
@include tg
}
@mixin h2 {
@include tg
}
....
如何使用循环创建@mixin 库?
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?
推荐答案
本质上,您指的是 SCSS
产生 SCSS
.这称为元编程.在 SASS
中是不可能的.除非 SASS 发明了某种技术或者你有另一种编译为 SCSS
的语言.
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.
这篇关于如何在sass中使用循环生成多个mixin(mixin lib)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文