【问题标题】:angular material text color using themes使用主题的角度材质文本颜色
【发布时间】:2018-09-25 15:35:23
【问题描述】:

我正在使用带有原色和强调色的角材质主题。我有两个不同的主题定义为最终用户可以动态更改的橙色和绿色。 theme.scss 如下所示

@import '~@angular/material/theming';

@include mat-core();

@mixin widget-theme($theme) {
    $primary: map-get($theme, primary);
    $accent: map-get($theme, accent);

    .fa-icon {
      color: mat-color($primary);
    }

    .fa-table-data-row-selected {
        background-color: mat-color($accent) !important;
        color: #152A23
    }

    .fa-text-link {
        color: #2A5D9F;
    }
  }



$custom-primary: mat-palette($mat-blue-grey,500);
$custom-accent:  mat-palette($mat-light-blue, A200);
$custom-warn:    mat-palette($mat-red);
$custom-theme: mat-light-theme($custom-primary, $custom-accent, $custom-warn);

@include angular-material-theme($custom-theme);
@include widget-theme($custom-theme);

//Orange theme
$ora-primary: mat-palette($mat-orange, 800);
$ora-accent:  mat-palette($mat-deep-purple, A100);
$ora-theme: mat-light-theme($ora-primary, $ora-accent);

.orange-theme {
    @include angular-material-theme($ora-theme);
    @include widget-theme($ora-theme);
}

//green theme
$green-primary: mat-palette($mat-green, 800);
$green-accent:  mat-palette($mat-lime, A700);
$green-theme: mat-light-theme($green-primary, $green-accent);

.green-theme {
    @include angular-material-theme($green-theme);
    @include widget-theme($green-theme);
}

我的整体配色方案使用原色和强调色非常出色。但是,请注意我有一个表的用例,并且使用带有 css fa-table-data-row-selected 的强调色来使用选定的行颜色。所选行的文本颜色当前是硬编码的。显然,这不适用于所有强调色,并且可能看起来完全不可读。因此,这也应该根据选择的主题动态更改。

这里有什么建议?我不能清楚地使用原色或强调色,因为那可能看起来不是最好的。它可能需要一些其他变量,该变量的值取决于选择的主题。

【问题讨论】:

    标签: css angular sass themes angular-material2


    【解决方案1】:

    使用调色板颜色的“对比”颜色:

    color: mat-color($accent, default);
    
    contrast-color: mat-color($accent, default-contrast);
    

    对于数字色调键,您可以使用mat-contrast 而不是mat-color

    color: mat-color($accent, 500);
    
    contrast-color: mat-contrast($accent, 500);
    

    稍微了解theming 的内部结构会非常有用。

    【讨论】:

    • 垫子对比($accent);对我不起作用,但第二版可以。第一次编译失败
    • 使用default-contrast 给了我另一种颜色,而不仅仅是default
    • @John yes - default-contrastdefault 应该是不同的颜色。
    • 好的,你写的答案是一样的,所以我很困惑。也许我读错了。不过感谢您的澄清。
    • 我不相信有一个 default 添加到对比,所以你必须指定说 500 例如mat-contrast($accent, 500) 或使用mat-color($accent, default-contrast)
    猜你喜欢
    • 2018-09-14
    • 1970-01-01
    • 2018-05-27
    • 2016-02-23
    • 1970-01-01
    • 2018-10-12
    • 1970-01-01
    • 1970-01-01
    • 2016-01-19
    相关资源
    最近更新 更多