提问人:Victor 提问时间:9/28/2023 最后编辑:Victor 更新时间:9/28/2023 访问量:44
在 Rails 7 上访问 Bootstrap 5 变量
Access Bootstrap 5 variables on Rails 7
问:
使用 Rails 7 和 Bootstrap 5。我希望其他 SCSS 能够访问 Bootstrap 变量,这样我就不必再次重新定义。但是通过以下设置,我得到了.Error: Undefined variable:
这是我的设置:
# application.scss
@import "bootstrap_overrides/bootstrap_custom";
@import "bootstrap_overrides/bootstrap_components";
@import "global";
@import "pages";
# bootstrap_overrides/bootstrap_custom.scss
# this is where I override the default values in Bootstrap variables
# this works fine
$font-family-monospace: "Ubuntu Mono", SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
# bootstrap_overrides/bootstrap_components.scss
# basically a copy of https://github.com/twbs/bootstrap-rubygem/blob/main/assets/stylesheets/_bootstrap.scss so that I can enable/disable components without bloating the final CSS
@import "bootstrap/mixins/banner";
@include bsBanner("");
// scss-docs-start import-stack
// Configuration
@import "bootstrap/functions";
@import "bootstrap/variables";
@import "bootstrap/variables-dark";
@import "bootstrap/maps";
@import "bootstrap/mixins";
@import "bootstrap/utilities";
...
# global.scss
# this is where the problem lies where I can't access $font-family-monospace, nor can I access any bootstrap variables like $black, etc.
.brand {
font-family: $font-family-monospace;
color: #ffffff;
}
编辑:如果我将所有这四个SCSS文件放在子目录“bootstrap_overrides”中,那么我就可以访问所有变量。但是我必须将它们放在子目录中app/assets/stylesheets/bootstrap_overrides
答: 暂无答案
评论
@use
规则将变量导入到你需要它们的作用域中。