Reputation: 1849
Is it possible to change the size of the checkbox in an Angular Material Selection List? I've tried changing the size of the mat-pseudo-checkbox
in CSS but that results in the checkmark not being placed properly:
mat-pseudo-checkbox {
height: 10px;
width: 10px;
}
Is there another selector that I need to adjust to correct this?
Upvotes: 11
Views: 19300
Reputation: 11
Setting those 2 variables in an scss file worked for me :
--mdc-checkbox-state-layer-size: 26px;
--mdc-checkbox-state-size: 16px;
Upvotes: 1
Reputation: 1
Works with 17.0.3
this affects the https://material.angular.io/components/checkbox
"* 2" - this is your value, how many times to increase
the value of how many times to increase should be the same for: /* from angular material: --mdc-checkbox-state-layer-size and --mdc-checkbox-state-size
/* from angular material: --mdc-checkbox-state-layer-size */
/* custom for your convenience: --mdc-checkbox-state-size */
:root {
--mdc-checkbox-state-layer-size: calc(40px * 2);
--mdc-checkbox-state-size: calc(18px * 2);
}
.mdc-checkbox {
flex: 0 0 var(--mdc-checkbox-state-size) !important;
width: var(--mdc-checkbox-state-size) !important;
height: var(--mdc-checkbox-state-size) !important;
padding: calc((var(--mdc-checkbox-state-layer-size) - var(--mdc-checkbox-state-size)) / 2) !important;
}
.mat-mdc-checkbox-touch-target {
width: calc(var(--mdc-checkbox-state-layer-size) + 8) !important;
height: calc(var(--mdc-checkbox-state-layer-size) + 8) !important;
}
.mdc-checkbox .mdc-checkbox__background {
top: calc((var(--mdc-checkbox-state-layer-size) - var(--mdc-checkbox-state-size)) / 2) !important;
left: calc((var(--mdc-checkbox-state-layer-size) - var(--mdc-checkbox-state-size)) / 2) !important;
width: var(--mdc-checkbox-state-size) !important;
height: var(--mdc-checkbox-state-size) !important;
}
Upvotes: 0
Reputation: 41
I was facing the similar issue and tried the below CSS, which seems to work in Angular 8:
::ng-deep .mat-checkbox .mat-checkbox-inner-container {
width: 30px;
height: 30px;
}
I have added a sample width and height; please customize these to what you need.
Upvotes: 4
Reputation: 6066
With Angular 7 I succeeded with:
mat-checkbox ::ng-deep .mat-checkbox-inner-container {width: 30px;height: 30px;}
Upvotes: 13
Reputation: 7132
Yes, the checkmark is just a pseudo element within the checkbox. You can override it's styles the same way as with the box itself.
For your case with the 10px box size the following CSS would work (for other sizes the values need to be adjusted):
.mat-pseudo-checkbox-checked::after {
top: 0px;
left: -1px;
width: 6px;
height: 2px;
}
Upvotes: 4