简体   繁体   English

更改Bootstrap材质主题的颜色

[英]Changing the colors of Bootstrap Material theme

I am working on an app, where I want to use a more deep-orange color style and have tried to override certain variables from the sass version of the files, but when I compile it using gulp it does not change. 我正在开发一个应用程序,该应用程序要使用更深橙色的颜色样式,并尝试覆盖sass版本的文件中的某些变量,但是当我使用gulp进行编译时,它不会改变。 Another thing that is weird is that when I use the sass version, the default colors are blue/indigo, but when just using the precompiled css from the github repo, it uses the teal color style. 另一件事很奇怪,就是当我使用sass版本时,默认颜色是blue / indigo,但是当只使用github repo中的预编译css时,它使用了深青色颜色样式。 I have the following in my app.scss file 我的app.scss文件中包含以下内容

@import "vendor/bootstrap/_bootstrap";
@import "vendor/bootstrap-material/bootstrap-material-design";
@import "vendor/material/ripples";

I tried to override variables by adding the variables that I wanted to change, such as the link-color, but no luck 我尝试通过添加要更改的变量来覆盖变量,例如链接颜色,但是没有运气

@import "vendor/bootstrap/_bootstrap";
@import "vendor/bootstrap-material/bootstrap-material-design";
$link-color: $red !default;
@import "vendor/material/ripples";

Does anyone know how to change the overall color style of the theme? 有谁知道如何更改主题的整体颜色样式?

为了更改Bootstrap变量的默认值,您需要在实际导入引导程序部分之前对其进行定义-确保对它应用!default标志,以使其无法被覆盖。

The issue could be that SASS partials should start with an underscore, or the file would otherwise compiled to a CSS file. 问题可能是SASS局部词应该以下划线开头,否则该文件将被编译为CSS文件。

Since vendor/bootstrap-material/bootstrap-material-design doesn't start with an underscore, it is probably being compiled into CSS without taking the variables defined after the @import into account. 由于vendor/bootstrap-material/bootstrap-material-design并非以下划线开头,因此可能会将其编译为CSS,而不会考虑@import之后定义的变量。

I'd also like to mentioned that as of now ( Until the next major release supporting Bootstrap4 ), Bootstrap Material Design projects sass files are automatically generated from LESS files. 我还想提到一下,到目前为止( 直到下一个支持Bootstrap4的主要版本发布 ), Bootstrap Material Design项目的sass文件都是从LESS文件自动生成的。 So in case prefixing with underscore doesn't help, you'll have better luck modifying the LESS files and compiling CSS or generating SASS files. 因此,如果在下划线前添加前缀没有帮助,那么最好修改LESS文件并编译CSS或生成SASS文件。

When changing Bootstrap styles/themes, I find the browser's Inspector to be very useful. 更改Bootstrap样式/主题时,我发现浏览器的Inspector非常有用。

  • In Firefox: Tools > Web Developer > Inspector 在Firefox中: 工具> Web开发人员>检查器
  • In Safari: Develop > Show Web Inspector 在Safari中:“ 开发”>“显示Web检查器”

Select an element in the page, and it shows all CSS styles being applied to it in hierarchical order (ie styles that are being applied correctly, but overridden by another style that takes precedence). 在页面中选择一个元素,它会显示所有按层次结构顺序应用到它的CSS样式(即正确应用的样式,但被其他优先的样式覆盖)。 Often, something is being modified by an element I didn't realize or is called something different than I thought. 通常,某些事情会被我没有意识到的元素修改,或者被称为与我想像的有所不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM