Angular 6 Material - Hues and How to change the color of mat radio button

我与影子孤独终老i 提交于 2020-05-09 04:51:29

问题


How can I change the color of the using CSS?

Saw on another post that if I use the following code, it would change it, but I had no luck with it so far.

.mat-radio-button.mat-accent .mat-radio-ripple .mat-ripple-element {
    background-color:rgb(255, 37, 37);
  }

.mat-radio-button.mat-accent.mat-radio-checked .mat-radio-outer-circle {
    border-color: rgb(66, 134, 244);
}

.mat-radio-button.mat-accent .mat-radio-inner-circle {
    background-color: rgb(66, 134, 244);
}

Also, how could I use the rest of the color hues?

<mat-radio-button color="accent">Hello, World</mat-radio-button>

Let's say that I want to use from the Accent color, the hue of 300 or A100, how would I go about to doing that?

I've tried using accent-100 and accent hue-100 but, it doesn't work


回答1:


add this css in your style.css/style.scss

Stackblitz

style.css/style.scss

.mat-radio-button.mat-accent.mat-radio-checked .mat-radio-outer-circle{
  border-color:rgb(66, 134, 244); 
}

.mat-radio-button.mat-accent .mat-radio-inner-circle{
  color:rgb(66, 134, 244);
  background-color:rgb(66, 134, 244) ;
}

.mat-radio-button.mat-accent .mat-radio-ripple .mat-ripple-element {
    background-color:rgb(255, 37, 37,.26);
}



回答2:


You can set custom color using following approach:

Put this code in your module declaration:

providers: [{
    provide: MAT_RADIO_DEFAULT_OPTIONS,
    useValue: { color: 'accent' },
}]


来源:https://stackoverflow.com/questions/52552284/angular-6-material-hues-and-how-to-change-the-color-of-mat-radio-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!