【问题标题】:How to assign the mixin $variable in scss file to an html element's class如何将 scss 文件中的 mixin $variable 分配给 html 元素的类
【发布时间】:2019-06-10 20:08:52
【问题描述】:

在我的 component.scss 文件中,我有 mixin 变量,我正在尝试为 div 元素设置波纹颜色。

如果我在 HTML 中设置直接颜色值例如:[matRippleColor]="red",则应用波纹颜色并工作

但是,如果我将 mixin 变量的名称scss 类名称 赋予 [matRipplecolor],则波纹颜色不应用 .

component.scss

@import '~@angular/material/theming';
@mixin dashboard-component-theme($bg-ripple) {

    .rippleCOLOR {
        background-color: $bg-ripple;
        color: $bg-ripple;
    }
}

component.html飞起来

<!-- WORKING: Direct Color value -->
<div matRipple [matRippleColor]="red"> Some text </div>


<!-- NOT WORKING: mixin variable -->
<div matRipple [matRippleColor]="$bg-ripple"> Some text </div>

<!-- NOT WORKING: scss class name -->
<div matRipple [matRippleColor]="rippleCOLOR"> Some text </div>

需要从 scss 文件中的 mixin 变量中设置波纹颜色

【问题讨论】:

  • AFAIK,您只能传递有效的 CSS 颜色代码。 (例如,您可以使用redrgba(200, 200, 200, 1)。)

标签: angular-material2 scss-mixins


【解决方案1】:

你不能在 HTML 文档/元素中使用 scss,因为你需要将它编译成 css..

下面是一些 youtube 教程.. scss install and compile

实际上很奇怪,因为很久以前我很生气为什么我的 scss 无法正常工作.. 我认为这完全与服务器设置有关:S

【讨论】:

  • 是的..我太沮丧了..过了一段时间做了一些肮脏的解决方法,它有所帮助..
  • 我希望 youtube 视频可以帮助你 :) 玩得开心编程
猜你喜欢
  • 2020-12-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-16
相关资源
最近更新 更多