Set preserveAspectRatio of SVG in mat-icon - css

I have a mat-icon with an SVG image:
<mat-icon [svgIcon]="getIcon()"></mat-icon>
The generated html looks something like this:
<mat-icon _ngcontent-plf-c14="" class="mat-icon notranslate mat-icon-no-color" role="img" aria-hidden="true" ng-reflect-svg-icon="some-icon">
<svg width="100%" height="100%" viewBox="0 0 288 78" fill="none" xmlns="http://www.w3.org/2000/svg" fit="" focusable="false" preserveAspectRatio="xMidYMid meet">
<path d="M252 1H3L37 38.5L3 76.5H252L286.5 38.5L252 1Z" fill="#3ED8C3" stroke="#1D4477" stroke-width="2"></path>
</svg>
</mat-icon>
All of that is fine and dandy except for the preserveAspectRatio bit. Angular always inserts
preserveAspectRatio="xMidYMid meet"
into the SVG but I want to have
preserveAspectRatio="none"
and I don't know how to get that.
Is there some way with HTML or CSS to change the preserveAspectRatio attribute of the generated SVG inside a mat-icon?

Related

SVG Color Change on Hover Effect

svg are somewhat tricky. I have some social icons with svg code and when I tried to color change on hover effect, it didn't want to change the color. My svg code looked like this.
<svg aria-hidden="true" width="30px" focusable="false" role="img" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 24 24">
<path class="social-icon contact-icon" d="M19.9,2H4.1C3,2,2,3,2,4.1v15.7C2,21,3,22,4.1,22h6.1v-6.8H7.5V12h2.8V9.6c0-2.8,1.7-4.3,4.2-4.3c1.2,0,2.5,0.2,2.5,0.2v2.7
h-1.4c-1.4,0-1.8,0.9-1.8,1.7V12h3.1l-0.5,3.2h-2.6V22h6.1c1.2,0,2.1-1,2.1-2.1V4.1C22,3,21,2,19.9,2z" />
</svg>
When you have path inside the svg tag just like me, you need to indicate the path to make it change the color.
So the css that solved my issue was:
svg:hover .social-icon {
fill: #color
}
svg:hover{fill: red}
<svg aria-hidden="true" width="30px" focusable="false" role="img" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 24 24">
<path class="social-icon contact-icon" d="M19.9,2H4.1C3,2,2,3,2,4.1v15.7C2,21,3,22,4.1,22h6.1v-6.8H7.5V12h2.8V9.6c0-2.8,1.7-4.3,4.2-4.3c1.2,0,2.5,0.2,2.5,0.2v2.7
h-1.4c-1.4,0-1.8,0.9-1.8,1.7V12h3.1l-0.5,3.2h-2.6V22h6.1c1.2,0,2.1-1,2.1-2.1V4.1C22,3,21,2,19.9,2z" />
</svg>

how to verify the SVG icons using robot framework

I need to validate the SVG icon for a drop down list items SVG icon. Each items having unique SVG icon. How can i validate the SVG icon using robot framework.
<span _ngcontent-c16="" class="flexColumnStatic role" style="height:20px; width: 25px; padding-left:4px;"><!----><mat-icon _ngcontent-c16="" class="roleIcon mat-icon mat-icon-inline" inline="true" role="img" aria-hidden="true"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 18 18" fit="" height="100%" width="100%" preserveAspectRatio="xMidYMid meet" focusable="false"><defs><path id="__2CNlSzv__editor-a" d="M7,21.2505178 L7,25 L10.7494792,25 L21.8079433,13.9415271 L18.0584641,10.1920448 L7,21.2505178 Z M24.7075406,11.0419275 C25.0974865,10.6519813 25.0974865,10.0220683 24.7075406,9.63212214 L22.3678656,7.29244522 C22.18106,7.1052184 21.9274444,7 21.6629635,7 C21.3984826,7 21.144867,7.1052184 20.9580614,7.29244522 L19.1283155,9.12219255 L22.8777948,12.8716748 L24.7075406,11.0419275 Z"></path></defs><g fill="none" fill-rule="evenodd" transform="translate(-7 -7)"><rect width="32" height="32"></rect><use fill="#000" fill-rule="nonzero" xlink:href="#__2CNlSzv__editor-a"></use></g></svg></mat-icon></span>

SVG <view> bug in macOS Safari

I'm trying to create an SVG sprite that can be used both as bg and as inline svg via .
The following SVG mostly works:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1">
<!-- symbols: used for inline SVGs via <use> -->
<symbol id="tsg-en-logo" viewBox="0 0 100 11.1">
<path fill="#0CA8D0" d="M0,2h1..."/>
</symbol>
<symbol id="chevron-down" viewBox="0 0 200 123.9">
<g fill="#0CA8D0">
<path d="M49..."/>
</g>
</symbol>
<!-- views: used for bg images -->
<view xmlns="http://www.w3.org/2000/svg" id="tsg-en-logo-bg" width="100" height="11.1" viewBox="0 0 100 11.1"/>
<view xmlns="http://www.w3.org/2000/svg" id="chevron-down-bg" width="200" height="123.9" viewBox="0 12 200 123.9"/>
<!-- uses: shown when acceses directly on the browser -->
<use xlink:href="#tsg-en-logo" x="0" y="0" width="100" height="11.1" id="u-tsg-en-logo"></use>
<use xlink:href="#chevron-down" x="0" y="12" width="200" height="123.9" id="u-chevron-down"></use>
</svg>
The problem is that when used as a BG, macOS Safari looses the proportions.
See full SVG here: https://cdn.rawgit.com/42pe/7a3a0193d3a142e7d93601340e6ee8fc/raw/81a7b0598b7179bdc071bba87569d53e2a7651e7/test.svg
And working fiddle: https://jsfiddle.net/42pe/Lragjqef/1/
Any idea why or how to fix? This works fine on Chrome, Firefox, IE11 and Edge!

Weird blue underline on svg hover

I have svg for social media icon and everytime I hover on it, it creates this blue underline and nothing seems to take it off. How can I remove it?
Here's how I include it.
<a class="footer-socialmedia-icons" style="padding-right:0.5rem;" target="_blank" href="https://www.facebook.com">
<img width="35px" height="35px" src="/files/IMG/facebook.svg" alt="facebook logo" class="">
</a>
EDIT:
here's the svg:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="50px" height="50px" viewBox="0 0 50 50" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 41.1 (35376) - http://www.bohemiancoding.com/sketch -->
<title>facebook</title>
<desc>Created with Sketch.</desc>
<defs></defs>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="facebook" fill="#DBC5DA">
<path d="M24.826,0 C11.137,0 0,11.137 0,24.826 C0,38.514 11.137,49.652 24.826,49.652 C38.514,49.652 49.652,38.514 49.652,24.826 C49.652,11.137 38.516,0 24.826,0 Z M31,25.7 L26.961,25.7 L26.961,40.096 L20.976,40.096 L20.976,25.7 L18.131,25.7 L18.131,20.612 L20.976,20.612 L20.976,17.321 C20.976,14.964 22.096,11.281 27.016,11.281 L31.451,11.298 L31.451,16.237 L28.232,16.237 C27.708,16.237 26.963,16.499 26.963,17.623 L26.963,20.613 L31.523,20.613 L31,25.7 Z" id="Shape"></path>
</g>
</g>
</svg>
EDIT
As it turns out, the blue line is underneath all tags. Tried text-decoration:none on but it doesn't do a thing.
Some browsers add a border to images in a elements to show them as clickable links.
If you don't want that, add
a img {border:none}
to your CSS.
This is not connected to SVG by the way; it happens on all images inside links.

SVG icon changes when SVG sprite set to display:none

If I embed an SVG sprite
<svg class="hidden-svg" version="1.1" id="Layer_2" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="208px" height="104px" viewBox="0 0 34 34" enable-background="new 0 0 34 34" xml:space="preserve" >
<g id="phone2">
.....
</g>
</svg>
and reference an embedded icon as follows:
<svg viewBox="1 1 32 32" class="icon">
<use xlink:href="#phone2"></use>
</svg>
If is set the SVG sprite to:
.hidden-svg {
display: none;
}
It changes the look of my icon. See jsbin here.
What can I do to avoid changing the icon?
Use visibility:hidden instead of display:none and make the original SVG width="0" and height="0" so that it doesn't take up space.

Resources