【问题标题】:Changing primary color in Bootstrap is not working? [closed]在 Bootstrap 中更改原色不起作用? [关闭]
【发布时间】:2021-06-03 15:30:02
【问题描述】:

我正在创建一个 react 应用,并且我已经安装了 Bootstrap React。

我想改变原色,也就是蓝色,所以我去了bootstrap/scss/variable.scss

然后我更改了以下内容:

$blue: #445448 !default;

因此,更改所有$primary: $blue !default;

但是,原色还是给我蓝色?

我再次停止了我的服务器 npm start,但没有任何工作。

【问题讨论】:

  • 不要使用 !default .. 使用 $blue: #445448;

标签: css reactjs bootstrap-4


【解决方案1】:

例如,您应该添加一个名为 custom.scss 的文件并添加以下内容:

// override Bootstrap variables here
// override the primary Bootstrap color
$primary: #12a2f9;

@import "~bootstrap/scss/bootstrap"

请注意,您应该在实际引导导入之前添加变量覆盖。

并在main.scss 之前或App.jsindex.js 中的引导导入之后导入此文件

编辑:假设这是您的项目根结构,请执行以下操作:

成分/ 应用程序.js 主文件 自定义.scss index.js 应用程序.test.js

您将在App.js 中写下这个,例如:

import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
// This import contains the custom variables written above
import "./custom.scss";
// This import contains the actual scss code
import "./main.scss";

ReactDOM.render(
    <App />,
  document.getElementById("root")
);

【讨论】:

  • 感谢您的回答!需要明确的是,(我是新手)我必须在 node_modules\bootstrap\scss 中创建一个 custome.scss 吗?然后,在其中写入 $primary: #12a2f9;并将其导入 bootstrap.sccs 并在导入顶部使用 @import "custom" ?在我的 index.js 中导入自定义,在我的 import 'bootstrap/dist/css/bootstrap.min.css';
  • @JéromeBORGA,这取决于您项目中的目录结构,但是不,该 custom.scss 文件将位于 css 文件夹或项目的根目录中,因为您将其导入应用程序.js 或 index.js 文件。我将编辑答案以包含我在此处描述的内容。
  • @JéromeBORGA 我已经更新了答案,请看看这是否对你有帮助。
  • 好的,非常感谢,我正在尝试这个,我会回来支持你的!!
  • 好的,首先我的 boostrap 是以这种方式导入的: import 'bootstrap/dist/css/bootstrap.min.css';在 index.js 所以在此之前,我写了 import './styles/custom.scss';仍然,我得到蓝色作为原色:(我错过了什么?编辑:好的,所以我删除了 boottrap.min.css 的导入并且它起作用了,但是我缺少一些引导元素
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-02-28
  • 2015-09-12
  • 2016-04-15
  • 1970-01-01
  • 2016-02-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多