How to change color for mat-divider?
Asked Answered
G

3

19

Is it possible to change mat-divider color? I tried the following, it didn't work

component.html

<mat-divider class="material-devider"></mat-divider>

component.scss

.material-devider {
    color: red
}
Gristede answered 9/1, 2020 at 19:57 Comment(2)
It's possible, and that's how you would do it. You likely have another rule overriding that with higher specificity. Try inspecting it with the F12 debugger.Louisalouisburg
You can use the !important keyword here.Memorialize
D
28

Yes, you can.

You need to overrule .mat-divider class styling in your own written CSS and change the border-top-color property.

.mat-divider {
    border-top-color: rgba(0, 0, 0, 0.12);
}

is the default styling by Angular Material.

.mat-divider {
    border-top-color: red;
}

This should be enough to change it (if your CSS gets rendered later than Material's). Otherwise adding increased specificity to your CSS class will help (f.e..mat-divider.mat-divider).

StackBlitz example for this case.

Danged answered 9/1, 2020 at 20:6 Comment(0)
B
2

To change the color mat-divider simply change the border-top-color property of .mat-divider class.

.mat-divider {
  border-top-color: red;
}

https://www.angularjswiki.com/angular/angular-material-divider-mat-divider-example/#mat-divider-color

Bopp answered 9/1, 2020 at 21:0 Comment(0)
P
0

If you use

  <mat-divider class="mat-divider" [vertical]="true"></mat-divider>

Then the change is with the border-right-color:

.mat-divider {
    border-right-color: red;  
}
Primitivism answered 13/3 at 23:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.