如何在Angular组件中使用Bootstrap SCSS函数?

萨马耶

我无法理解如何在Angular组件(例如theme-color或)中使用某些Bootstrap SCSS函数color

我有一个component.scss看起来像:

.card {
  cursor: pointer;
  &:hover {
    background-color: theme-color("primary");
  }
}

但这是行不通的,我可能会添加错误。如果我@import '~node_modules/bootstrap/scss/bootstrap';在文件前添加::但是,它没有考虑我的全局样式,而是使用默认颜色。

如果仅导入函数SCSS,则它将无法理解其他导入,例如包含var的导入$color

在我的全局styles.scss样式表中进行编辑时,一切正常

似乎关于视图封装的事情正在阻止从Bootstrap过滤到我的组件SCSS的全局SCSS函数,但是我无法完全了解它是什么。

那么,如何将全局的SCSS函数(例如Bootstrap的函数)放入我的单个组件SCSS文件中?

JB Nizet

这是我的方法。

  1. 在styles.scss中:

    @import 'custom-bootstrap';
    // + custome global scss rules
    
  2. 在custom-bootstrap.scss中

    @import './common';
    @import '~bootstrap/scss/root';
    @import '~bootstrap/scss/reboot';
    // + other imports copied from the standard bootstrap.scss file
    // some of them being commented out because I don't need them
    
  3. 在common.scss

    // potential bootstrap variable overrides here
    @import '~bootstrap/scss/functions';
    @import '~bootstrap/scss/variables';
    @import '~bootstrap/scss/mixins';
    
  4. 在任何组件的scss文件中:

    @import '../../common'; // the path may of course vary depending on the depth
    // and here I can use any bootstrap (or custom) variable, mixin or function
    

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何使用函数中的SCSS变量进行计算

如何在React组件的返回函数中使用IIFE?

如何在Laravel中使用Scss文件

如何在CodeSandbox中使用Scss文件?

如何在angular 7中使用SCSS mixins

如何在SCSS中使用静态帮助函数(javascript)设置不同环境下图像的基本URL?

在Angular中使用动态注入组件时如何访问函数

如何在Angular中全局包含Bootstrap的scss变量,而不必每次都在每个组件中导入主题?

如何分隔scss函数的返回值

如何在Angular的构造函数中使用@Inject文本测试组件

如何在React函数组件中使用数组状态?

如何在角度组件的styles.scss中使用媒体查询?

如何在Angular中使用两个构造函数

如何在Angular组件/ TypeScript中使用徽标滑块JavaScript函数?

在 NativeScript 中使用 Angular 为组件特定的 .scss Sass

如何在 angular 4 中使用回调函数?

Angular 服务在组件的函数中使用

如何在 React Native 中使用函数渲染组件

如何在 ReactJs 组件中使用外部 JavaScript 函数?

如何使用scss函数或mxin生成关键帧动画

如何在 Vue 本地组件中使用函数

如果使用函数设置值,则 SCSS 变量中的值不同

如何在 reactjs 组件中使用使用 scalajs 导出的函数?

如何在 Node/Angular/React 中使用 scss 函数

如何在类组件的函数中使用道具?

如何在reactjs中使用钩子将类组件转换为函数组件

如何在库 angular 中使用 scss 文件创建组件

如何在输入字段中使用 scss

如何在scss中使用js变量?