gpt4 book ai didi

css - 如何避免 Sass 变量名在 _variables.scss 中重复?

转载 作者:行者123 更新时间:2023-12-04 01:24:27 24 4
gpt4 key购买 nike

我有 _variables.scss,其结构如下 BEM naming conventions .

$slot-width: 100px;
$slot-height: 10px;
$slot-title-width: 80px;
$slot-title-height: 10px;

我在重复变量名 $slot-。有没有办法做这样的事情:

$slot {
&-width: 100px;
&-height: 10px;
&-title {
&-width: 80px;
&-height: 10px;
}
}

它编译成上面的?

最佳答案

你可以使用 Sass Maps :

$slot: (
"width": 100px,
"height": 10px,
"title": (
"width": 80px,
"height": 10px
)
);

此外,这里有一篇关于 getting values out of deep Sass maps 的好文章.

但是,继续使用带有连字符的常规变量可能会更容易,因为您已经这样做了。

关于css - 如何避免 Sass 变量名在 _variables.scss 中重复?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62153923/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com