我如何更改角材料md-主按钮文本的颜色?

问题描述 投票:4回答:1

[我基本上不能为我的生活弄清楚如何使用角形材料设置按钮的文本颜色,而使用md-primary背景颜色设置其他任何颜色。

我用来创建主题的代码是

var customPrimary = {
        '50': '#7de3cf',
        '100': '#69dec8',
        '200': '#54dac0',
        '300': '#3fd5b8',
        '400': '#2dceaf',
        '500': '#28b99d',
        '600': '#23a48b',
        '700': '#1f8f79',
        '800': '#1a7a68',
        '900': '#166556',
        'A100': '#92e8d7',
        'A200': '#a7ecdf',
        'A400': '#bcf1e7',
        'A700': '#115044'
    };
    $mdThemingProvider
        .definePalette('customPrimary',
        customPrimary);
    $mdThemingProvider.theme('buttons')
        .primaryPalette('customAccent');

但是无论我尝试什么,除非我使用css和我要避免的#fff,否则我都可以将文本颜色设置为!important,因为这意味着将覆盖多个选择器。

angularjs angularjs-material
1个回答
8
投票

docs

angular.module('myApp', ['ngMaterial'])
.config(function($mdThemingProvider) {
  $mdThemingProvider.definePalette('amazingPaletteName', {
    '50': 'ffebee',
    ...
    'A700': 'd50000',
    'contrastDefaultColor': 'light',    // whether, by default, text (contrast)
                                        // on this palette should be dark or light
    'contrastDarkColors': ['50', '100', //hues which contrast should be 'dark' by default
     '200', '300', '400', 'A100'],
    'contrastLightColors': undefined    // could also specify this if default was 'dark'
  });
  $mdThemingProvider.theme('default')
    .primaryPalette('amazingPaletteName')
});

这里重要的是contrastDarkColors / contrastLightColors。 “对比”颜色是按钮上显示的文本(或图标)颜色。

我猜你会想要类似的东西

'contrastDefaultColor': 'light',
'contrastDarkColors': ['50', '100', '200', '300', 'A100', 'A400']

编辑:如果您由于某种原因想要按钮上的颜色,则可以创建一个具有!important的类,例如,

.md-button.cyan-text {
    color: cyan !important;
}

<md-button class="md-primary md-raised cyan-text">Hello world</md-button>
© www.soinside.com 2019 - 2024. All rights reserved.