Change SVG Size In Angular Material 2 Using Vanilla CSS Or HTML
Answer :
It seems that library styles override your css inline declaration. Try maybe to add !important
declaration to your style: style="font-size: 16 !important"
or since you didn't provide more code, try to inspect this icon node, to check which style define the font-size.
Also check here
UPDATE:
Here is another possibly working solution. Add transform: scale(2);
style for svg element you want to resize, where 2 is 200% of actual size (of course you can also downsize them using for example 0.5 value for 50%). Here is working sample for the website with your icons and link to documnetation:
.size-24 button svg { width: 24px; height: 24px; transform: scale(2); }
I played with this for way too long.
I have a series of icons that I want to be scaled to fit in various mat-icon
sizes, but each icon needs a different scale so they appear balanced with the other icons - effectively increasing the size of the viewBox.
In the end this worked well enough:
mat-icon { width: 50px; height: 50px; display: flex; flex-shrink: 0; justify-content: center; outline: 1px dashed red; // for testing & ::ng-deep svg { align-self: center; } &.shrink-90 ::ng-deep svg { width: 90%; height: 90%; } &.shrink-80 ::ng-deep svg { width: 80%; height: 80%; } }
Then I create the mat-icon
with this, where iconCss='shrink-80'
<mat-icon svgIcon="{{ feature.name }}" [ngClass]="feature.iconCss"></mat-icon>
The mat-icon
itself can be scaled with whatever additional classes you want (just like you would for a normal icon). Then the 'shrinking' adjusts the size within the box.
Taking @mpro solution, I did some changes that work better for me ( I have custom icons so maybe that's the reason why):
mat-icon[size="2"]{ width: 48px; height: 48px; } mat-icon[size="2"] svg{ transform: scale(2); transform-origin: left top; }
or the scss solution:
@mixin iconSize($size){ &[size="#{$size}"]{ width: 24px*$size; height: 24px*$size; svg{ transform: scale($size); transform-origin: left top; } } }
Comments
Post a Comment