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

ass CSS

逆天凯

2020-03-23

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

我想到的是像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;
}

第2830篇《如何在不同的导入文件之间共享变量?》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

2个回答
番长 2020.03.23

是的,就是这样。

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

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

神无 2020.03.23

您需要;在该@import的末尾添加一个

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android