【发布时间】:2021-12-04 05:14:54
【问题描述】:
我正在尝试在我的 bootstrap/react/scss 设置中使用自定义颜色。我使用的自定义颜色是“清晰”。奇怪的是在按钮组件上使用 className="btn-clear" 确实使按钮具有自定义颜色(正确的行为),但是在 div 上使用 className="bg-clear" 只会使 div 变成白色,而不是自定义颜色(不正确行为)。所以自定义颜色似乎有效,但仅适用于 btn- 类。
Node-sass 没有构建,所以被 sass 取代。
这与我导入模块的顺序有关吗?
我正在使用 import '../../scss/custom.scss' 将 custom.scss 导入到我的主应用中
custom.scss
@import './vendors/bootstrap';
_bootstrap.scss
// Required
@import 'bootstrap/scss/functions';
@import 'bootstrap/scss/_variables';
// Import Overrides here
@import 'scss/themes/_bootstrap_overrides';
// Configuration
@import 'node_modules/bootstrap/scss/_utilities';
@import 'bootstrap/scss/_mixins';
// Layout & components
@import '../../../node_modules/bootstrap/scss/_root';
@import '../../../node_modules/bootstrap/scss/_reboot';
@import '../../../node_modules/bootstrap/scss/_type';
@import '../../../node_modules/bootstrap/scss/_containers';
@import '../../../node_modules/bootstrap/scss/_grid';
@import '../../../node_modules/bootstrap/scss/_forms';
@import '../../../node_modules/bootstrap/scss/_buttons';
@import '../../../node_modules/bootstrap/scss/_transitions';
// Helpers
@import '../../../node_modules/bootstrap/scss/_helpers';
// Utilities
@import '../../../node_modules/bootstrap/scss/utilities/_api';
_bootstrap_overrides.scss
$custom-colors: (
'gray': $gray-600,
'clear': #73bae1,
'clear-light': #c4e2f2,
'clear-dark': #54a6dc,
);
// Merge with bootstrap theme
$theme-colors: map-merge($theme-colors, $custom-colors);
package.json
{
"name": "",
"version": "0.1.0",
"private": true,
"homepage": "",
"dependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"bootstrap": "^5.1.3",
"luxon": "^1.26.0",
"prop-types": "^15.7.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"styled-components": "^5.2.3",
"web-vitals": "^1.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"cz-conventional-changelog": "^3.3.0",
"eslint": "^7.25.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.23.2",
"eslint-plugin-react-hooks": "^4.2.0",
"prettier": "2.2.1",
"sass": "^1.43.2"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}
提前致谢!
【问题讨论】:
标签: reactjs sass bootstrap-5