英文:
how to group mixins of same kind in scss
问题
我正在使用以下代码
@use 'rules.scss' as css;
@include css.mixin();
但我想要将 mixin 分组在我的主文件中
例如:包含 OS 网站布局规则的 mixin 应该分组在一起
然后我可以这样使用它们
@include css.OS.windowmixin();
我尝试过使用 @group 并将 mixin 嵌套,这是从 ChatGPT 的建议中得到的,但没有生效。
英文:
i am using the following code
@use './rules.scss' as css;
@include css.mixin();
but i want to group mixins in my main file
foreg:- mixins containing rules for OS website layout should be in one group
and i can use them as
@include css.OS.windowmixin();
i have tried @group and nesting mixins as a suggestion from chatgpt but it doesn't work
答案1
得分: 1
你可以将你的 mixin 分组放在一个名为 mixins 的文件夹中,像这样:
mixins
_group1Mixins.scss
_group2Mixins.scss
然后在同一文件夹中创建一个名为 _index.scss
的文件,通过添加前缀来引入所有 mixin 文件,如下所示:
@forward "_group1Mixins.scss" as group1-*;
@forward "_group2Mixins.scss" as group2-*;
现在在你的主文件中,你可以使用 @use
来导入它们。每个文件中的 mixin 将会相应地添加前缀,例如,要使用 _group1Mixins.scss
中的 mixin,你需要以 group1-
作为前缀。
@use "mixins/index" as mixins;
.myclass {
@include mixins.group1-myMixin();
}
英文:
You can group your mixins in separate scss files inside a mixins folder like this:
mixins
_group1Mixins.scss
_group2Mixins.scss
Then create an _index.scss
file in same folder that forwards all the mixin files by prefixing them:
@forward "_group1Mixins.scss" as group1-*;
@forward "_group2Mixins.scss" as group2-*;
Now in your main file you can import them using @use
. The mixins from each file will be prefixed accordingly for example to use a mixin from your _group1Mixins.scss
you will need to prefix it with group1-
.
@use "mixins/index" as mixins;
.myclass {
@include mixins.group1-myMixin();
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论