Bootstrap 5 (update 2021)
Bootstrap 5的方法仍然相同.
https://codeply.com/p/iauLPArGqE个
100
要更改Bootstrap 4 Sass中theme colors的primary或any,请设置适当的变量before导入bootstrap.scss
.这允许您的自定义SCSS覆盖!默认值.
$primary: purple;
$danger: red;
@import "bootstrap";
演示:https://codeply.com/go/f5OmhIdre3
在某些情况下,可能需要从另一个existing bootstrap 变量设置新 colored颜色 .为此@import首先导入函数和变量,以便在定制中引用它们...
/* import the necessary Bootstrap files */
@import "bootstrap/functions";
@import "bootstrap/variables";
$theme-colors: (
primary: $purple
);
/* finally, import Bootstrap */
@import "bootstrap";
演示:https://codeply.com/go/lobGxGgfZE
另见:this answer、this answer或changing the button color in (CSS or SASS)
也可以使用CSS only来更改原色,但它需要大量额外的CSS,因为有许多-primary
种变体(btn主色、alert 主色、bg主色、文本主色、表格主色、边框主色等)其中一些类在边界、悬停和活动状态上有轻微的 colored颜色 变化.因此,如果必须使用CSS,最好使用目标组件,例如更改primary button color.