How to customize the color of mat checkboxes in mat select options as seen below
<mat-form-field appearance="fill" style="width:49%">
<mat-label>Select Group</mat-label>
<mat-select [(ngModel)]="groupNames" name="group" multiple>
<mat-option *ngFor="let group of GroupList" [value]="groupName">
{{groupName}}
</mat-option>
</mat-select>
</mat-form-field>
I tried inspecting the elements and styles in browser and there was this class
.mat-pseudo-checkbox-full.mat-pseudo-checkbox-checked, .mat-pseudo-checkbox-full.mat-pseudo-checkbox-indeterminate {
background-color: var(--mat-full-pseudo-checkbox-selected-icon-color);
border-color: rgba(0, 0, 0, 0);
}
that was affecting the background color of the checkbox(which I want to customize) but when same class is over-rided in CSS file in my angular project, the changes are not reflecting
2
Answers
If you are using an earlier version of angular which has some other HTML. Just change the CSS styles to below. Applying the same concepts as the second part of this answer!
If you want to override the styles inside a component you need to use
::ng-deep
(Not Recommended) on the prefix of the class.Stackblitz Demo
Since
::ng-deep
is Not Recommended, you can use a class to achieve the same thing.First we specify
panelClass
to give the dropdown a custom class.Then in the global styles, we can add the class.
Stackblitz Demo
Assuming you are using Angular Material 3, add the following entry to your
style.scss
file.Good luck with your project.