twitter-bootstrap - Customizing Bootstrap using default Bootstrap variables
问题描述
I recently started the process of customizing Bootstrap for a project. We're on Bootstrap v5.1.1 for what it's worth.
I understand that because of !default
I need to define my customizations before importing Bootstrap variables. I've run into an issue where I want to use a default variable to define a customization. More specifically I'm trying to set $btn-font-weight
to bold. The line I tried is: $btn-font-weight: $font-weight-bold;
. This doesn't work because I'm not customizing $font-weight-bold
so it doesn't get defined until importing Bootstrap's defaults.
I found this question which recommends copying the Bootstrap variable as-is into the customization sass, but the answer is 6 years old so I'd like to know if there's a better way.
解决方案
在调用 Bootstrap 模块之前定义变量是改变 Bootstrap 自身构建方式的最佳(也是唯一)方法。Bootstrap 自己建议这样做:https ://getbootstrap.com/docs/4.0/getting-started/theming/ ,来自文章:
同一个 Sass 文件中的变量覆盖可以在默认变量之前或之后。但是,当覆盖 Sass 文件时,您的覆盖必须在导入 Bootstrap 的 Sass 文件之前进行。
我见过的最好的方法是创建一个包含所有覆盖变量的 _bootstrap-settings.scss 文件,然后在调用引导模块之前 @import 该文件,如下所示:
// Your variable overrides
$body-bg: #000;
$body-color: #111;
// Bootstrap and its default variables
@import "node_modules/bootstrap/scss/bootstrap";
推荐阅读
- postgresql - CTE 和 DML 语句的 PG 意外行为
- php - 为什么我得到数组到字符串的转换错误?
- sharepoint - Sharepoint 2013 Wiki 历史页面始终显示添加的第一个单词
- python - Python-Mysql插入查询
- html - 无法对齐连续 3 个元素。一个应该在左边,其余的应该居中
- amazon-s3 - Kafka S3 源连接器
- python - 我的 on_message 功能不再起作用
- elasticsearch - Elasticsearch 未在云 URL 中打开
- php - 如何在docker容器中访问主机的mongo db
- python - 将 pandas df 转换为嵌套字典