[英]How to create multiple themes in sass unsing sass modules feature?
在将模块引入 sass 之前,您可以通过以下方式制作主题样式表:
主题Dark.scss:
$color: black;
基按钮.scss:
button {
color: $color;
}
按钮.scss:
@import './_themeDark.scss'
@import './_baseButton.scss'
现在,模块被引入到 sass 中,@ @import
已被弃用。 如何使用sass模块达到同样的效果?
我正在寻找一种解决方案,其中一些文件用作部分样式表。 在主文件中,它们组合在一起形成将被导入的最终样式表。
我尝试过的:
@use
而不是@import
。 它不起作用,因为看不到来自其他模块的变量。@import
的解决方案更难维护。您可以使用 scss 映射来存储所有主题
$themes: (
theme1: (color: red),
theme2: (color: orange),
theme3: (color: yellow),
theme4: (color: green),
theme5: (color: blue)
);
使用这个地图是一个@each
循环。
@each $theme, $map in $themes {
.#{$theme} {
color: map-get($map, color);
}
}
在每个循环中,将这些值分别分配给$theme
和$map
。
$theme
- 主题名称$map
- 所有主题变量的$map
您现在使用map-get()
函数从$map
获取任何主题变量并为每个主题输出正确的属性。
@each $theme, $map in $themes {
.#{$theme} & { // <--- Notice the & here!
color: map-get($map, color);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.