2017-09-13 84 views
3

这是自举4.0 SASS

style.scss文件包含以下代码:

@import "../bootstrap/scss/bootstrap"; 

@import "colors"; 
@import "main"; 

_colors.scss文件包含以下代码:

$bg-white : white; 

$theme-colors: (
     primary: #333333 
) 

你可以看到我只是想重写$theme-color('primary'),但问题是它没有任何作用。

,如果我在文件style.scss开始转向@import "colors"它给了我以下错误:

error ../bootstrap/scss/_forms.scss (Line 284: $color: null is not a color for `rgba')

其实,style.scss文件编译为style.css文件和一个链接文件。

问:如何我可以覆盖使用SASS$theme-colorbootstrap-4

任何帮助将不胜感激,并提前致谢

干杯。

回答

4

这也得到了我。您需要在变量之前将functions.scss导入scss文件。

@import '../../node_modules/bootstrap/scss/functions'; 
@import 'assets/styles/variables'; 
@import '../../node_modules/bootstrap/scss/bootstrap'; 

您的路径可能不同。

这是Bootstrap 4 Beta 1.

+0

这是我找到的答案也为我自己。如果没有上述变量的函数,它不会正确编译'theme-color(“primary”)',因为函数内部有一个叫做'theme-color'的函数。 – micah

+0

确认目前似乎不起作用。事实上,当我尝试这个时候,它仍然会抛出错误。 –

2

我假设你已经使用npm安装Bootstrap 4 beta和你想自定义的引导SCSS没有node_modules修改源。

我这样做,是覆盖包含在variables.scss的引导变量的方法:

APP-styles.scss

// Custom SCSS variables I wish to override (see below) 
@import 'assets/styles/variables'; 

// Bootstrap 4 from node_modules 
@import '~bootstrap/scss/bootstrap.scss'; 

variables.scss

$theme-colors: (
    primary: $trump-hair, 
    secondary: $gandalf-hat, 
    success: $my-favorite-color, 
    info: #FBC02D, 
    warning: #FF5722, 
    danger: $color-of-melena, 
    light: #1B5E20, 
    dark: $bile-green 
); 

的覆盖引导主题颜色的方式实际上是由于被改变即将推出的测试版2.目前的要求是,覆盖时必须包含整个theme-colors Sass地图。在目前的测试版,不包括整个萨斯地图会:

Argument $color of darken($color, $amount) must be a color

请参阅本Github上issueCodepen更多的信息,以及你将如何能够覆盖主题颜色在测试的例子2.

+0

获取这些值的正确方法是什么?我在bootstrap scss文件中看到了主题颜色('blue'),但是我得到了错误.. – Notflip

+0

它只是一个Sass Map:map-get($ theme-colors,primary) –