gpt4 book ai didi

sass - 如何在不同的导入文件之间共享变量?

转载 作者:行者123 更新时间:2023-12-03 10:40:45 24 4
gpt4 key购买 nike

我想以模块化的方式使用 SASS。在下面的代码段中,您可以看到我考虑组织页面布局的一种方式。

我想到的是external variables in languages like C .

// file: some_page.scss  
//
// I want some variables from the fonts, colors partials
// to be visible to the buttons partial
// Is it possible?
// error: _buttons.scss (Line X: Undefined variable: "$color_blue")

@import "colors"
@import "fonts"
@import "buttons"

// in file: _colors.scss
$color_blue: blue;

// in file: _buttons.scss

.button {
background-color: $color_blue;
}

最佳答案

是的,它就是这样工作的。

只要_colors.scss在其他文件之前导入。

你可以在这里查看 Twitter Bootstrap 到 Sass 的端口:https://github.com/thomas-mcdonald/bootstrap-sass它以类似的方式使用变量。

关于sass - 如何在不同的导入文件之间共享变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13884389/

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