How to change position of svg on hover with a transition delay - html

I'm trying to move svg icons in my navbar to the left on hovering, which I'm able to do so, but I need the element to move smoothly through something like this transition : all .5s;
The issue is that svg tag doesn't accept transition property in css, so I tried to use the transition on the container, but that doesn't work, it just move instantly without transition effect.
HTML :
<div id="sidenav-icon-section">
<li>
<a href="/">
<img src="/assets/images/home.svg" alt="home" onload="SVGInject(this)">
</a>
</li>
</div>
I use the SVGInject library to transform my svg code in the browser, which results to this :
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Layer_1" x="0px" y="0px" width="64px" height="64px" viewBox="0 0 64 64" enable-background="new 0 0 64 64" xml:space="preserve" data-inject-url="http://localhost:4200/assets/images/home.svg" _ngcontent-c1="">
<polygon fill="none" stroke="#000000" stroke-width="2" stroke-miterlimit="10" points="32,3 2,33 11,33 11,63 23,63 23,47 39,47 39,63 51,63 51,33 62,33 "></polygon></svg>
Also I have another svg icon that has a path tag instead of polygon
CSS :
#sidenav-icon-section {
top: 25%;
position: relative;
li {
position: relative;
transition: all .5s;
&:hover svg {
left: 7%;
}
}
}
I tried applying the transition to and the "left" attribute to path and polygon elements but nothing happens at that point, they don't even move.

You are trying to set the attribute left on an element which position is static. Try a negative margin instead. Also you are applying the transition to the wrong element.
svg { transition: margin-left .5s }
li:hover svg {
margin-left: -7px;
}
<ul id="sidenav-icon-section">
<li class="item">
<a href="/">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Layer_1" x="0px" y="0px" width="64px" height="64px" viewBox="0 0 64 64" enable-background="new 0 0 64 64" xml:space="preserve" data-inject-url="http://localhost:4200/assets/images/home.svg"
_ngcontent-c1="">
<polygon fill="none" stroke="#000000" stroke-width="2" stroke-miterlimit="10" points="32,3 2,33 11,33 11,63 23,63 23,47 39,47 39,63 51,63 51,33 62,33 "></polygon></svg>
</a>
</li>
</ul>
the scss equivalent:
li {
svg { transition: margin-left .5s; }
&:hover svg {
margin-left: -7px;
}
}

Related

Background color of an svg

I need to change the INSIDE background color of a heart-shaped svg but with normal background it overflows and with fill it changes the border not the inside, any tips on how i might achive what i am looking for?
.heart {
width: 50%;
margin-left: 25%;
cursor: pointer;
}
.heart:active {
background-color: red;
overflow: hidden;
}
<svg class="heart" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Capa_1" x="0px" y="0px" viewBox="0 0 471.701 471.701" style="enable-background:new 0 0 471.701 471.701;" xml:space="preserve">
<g>
<path d="M433.601,67.001c-24.7-24.7-57.4-38.2-92.3-38.2s-67.7,13.6-92.4,38.3l-12.9,12.9l-13.1-13.1 c-24.7-24.7-57.6-38.4-92.5-38.4c-34.8,0-67.6,13.6-92.2,38.2c-24.7,24.7-38.3,57.5-38.2,92.4c0,34.9,13.7,67.6,38.4,92.3 l187.8,187.8c2.6,2.6,6.1,4,9.5,4c3.4,0,6.9-1.3,9.5-3.9l188.2-187.5c24.7-24.7,38.3-57.5,38.3-92.4 C471.801,124.501,458.301,91.701,433.601,67.001z M414.401,232.701l-178.7,178l-178.3-178.3c-19.6-19.6-30.4-45.6-30.4-73.3 s10.7-53.7,30.3-73.2c19.5-19.5,45.5-30.3,73.1-30.3c27.7,0,53.8,10.8,73.4,30.4l22.6,22.6c5.3,5.3,13.8,5.3,19.1,0l22.4-22.4 c19.6-19.6,45.7-30.4,73.3-30.4c27.6,0,53.6,10.8,73.2,30.3c19.6,19.6,30.3,45.6,30.3,73.3 C444.801,187.101,434.001,213.101,414.401,232.701z"/>
</g>
</svg>
Issues & Solutions
svg's path is an outline only
apply fill to the path instead of svg
.heart {
width: 50%;
margin-left: 25%;
cursor: pointer;
}
.heart:active path {
fill: red;
overflow: hidden;
}
<svg class="heart" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Capa_1" x="0px" y="0px" viewBox="0 0 471.701 471.701" style="enable-background:new 0 0 471.701 471.701;" xml:space="preserve">
<path d="m433.601,68.66767c-24.7,-24.7 -57.4,-38.2 -92.3,-38.2s-67.7,13.6 -92.4,38.3l-12.9,12.9l-13.1,-13.1c-24.7,-24.7 -57.6,-38.4 -92.5,-38.4c-34.8,0 -67.6,13.6 -92.2,38.2c-24.7,24.7 -38.3,57.5 -38.2,92.4c0,34.9 13.7,67.6 38.4,92.3l187.8,187.8c2.6,2.6 6.1,4 9.5,4c3.4,0 6.9,-1.3 9.5,-3.9l188.2,-187.5c24.7,-24.7 38.3,-57.5 38.3,-92.4c0.1,-34.9 -13.4,-67.7 -38.1,-92.4z" stroke="#000" fill="#fff"/>
</svg>

How to change font-size to a SVG?

I'm using a svg icon on my website.
here's the code I got from Adobe Illustrator:
<svg id="Livello_1" data-name="Livello 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448.05 436.7"><path d="M190.5,66.9l22.2-22.2a23.9,23.9,0,0,1,33.9,0L441,239a23.9,23.9,0,0,1,0,33.9L246.6,467.3a23.9,23.9,0,0,1-33.9,0l-22.2-22.2a24,24,0,0,1,.4-34.3L311.4,296H24A23.94,23.94,0,0,1,0,272V240a23.94,23.94,0,0,1,24-24H311.4L190.9,101.2A23.85,23.85,0,0,1,190.5,66.9Z" transform="translate(0 -37.65)"/></svg>
I've been able to change its color (in my css fill:#33453a;) but not its size (I tried with both font-size and width, but none of them worked).
The reason why I'm trying to do so is that I need an icon which color and size can be changed in :hover status.
This might be a tricky question. What you are intending to do is not possible as other people pointed out, but not being possible with font-size doesn't mean it is not possible to get it working as you are expecting.
If you look into a big project like react-icons you can get a glimpse of how they do it.
const computedSize = size || conf.size || "1em";
let className;
if (conf.className) className = conf.className;
if (props.className) className = (className ? className + ' ' : '') + props.className;
return (
<svg
stroke="currentColor"
fill="currentColor"
strokeWidth="0"
{...conf.attr}
{...attr}
{...svgProps}
className={className}
style={{ color: props.color || conf.color, ...conf.style, ...props.style}}
height={computedSize}
width={computedSize}
xmlns="http://www.w3.org/2000/svg"
>
{title && <title>{title}</title>}
{props.children}
</svg>
)
};
So you might have something similar like: <span style="font-size: 14px">hi <svg ...></svg></span>.
The trick is to assign with and height the em unit, which stands for ephemeral unit don't be confused with rem, you can read more about his in this post
What the em unit will do in your browser is to look at the closest definition of font-size and attach that one to the SVG context, that is how you get the same dimension.
Solution: add width:1em and height:1em
<svg height="1em" width="1em" id="Livello_1" data-name="Livello 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448.05 436.7"><path d="M190.5,66.9l22.2-22.2a23.9,23.9,0,0,1,33.9,0L441,239a23.9,23.9,0,0,1,0,33.9L246.6,467.3a23.9,23.9,0,0,1-33.9,0l-22.2-22.2a24,24,0,0,1,.4-34.3L311.4,296H24A23.94,23.94,0,0,1,0,272V240a23.94,23.94,0,0,1,24-24H311.4L190.9,101.2A23.85,23.85,0,0,1,190.5,66.9Z" transform="translate(0 -37.65)"/></svg>
You can not change the font size or font width because SVG is not a font. It is Scalable Vector Graphics. If you would have some text in your SVG then you could do something with the font from the text element.
In your case you have to add attribute width and height for SVG. And in hover of SVG you can change it like follows:
#Livello_1:hover
{
fill:#33453a;
width:48px;
height:48px
}
<svg id="Livello_1" width="36" height="36" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448.05 436.7"><path d="M190.5,66.9l22.2-22.2a23.9,23.9,0,0,1,33.9,0L441,239a23.9,23.9,0,0,1,0,33.9L246.6,467.3a23.9,23.9,0,0,1-33.9,0l-22.2-22.2a24,24,0,0,1,.4-34.3L311.4,296H24A23.94,23.94,0,0,1,0,272V240a23.94,23.94,0,0,1,24-24H311.4L190.9,101.2A23.85,23.85,0,0,1,190.5,66.9Z" transform="translate(0 -37.65)"/></svg>
To see the effect you have to move your mouse cursor over this SVG (in snippet, wich must be runned).
Since it does not contain a text with font, the better way is to use scale to increase the size. :
<style>
svg
{
transform: scale(1.3);
}
</style>
I guess you need to align and scale your svg icon relative to your font size.
It is kind of a 'team play' between svg and css:
In css we make sure our svg has a inline-block context, a height relative to the inherited font-sizes.
In svg we use seperate viewBox attributes for each icon.
If you need to adjust the baseline alignment or dimensions on :hover you need to avoid layout shifts e.g vertical-align would also some kind of leading to the next line – therefore we use a relative position and bottom offset.
/* just an example code to illustrate the scalability */
const fontSize= document.querySelector('.fontSize');
const layout = document.querySelector('.layout');
fontSize.addEventListener('change', function(e) {
let currentSize = +e.target.value;
layout.setAttribute('style', 'font-size:'+(1+currentSize)+'em');
});
/* svg will behave similarly to a character/glyph */
.svg-inline {
display: inline-block;
/* without a custom viewbox we have a square aspect ratio as default */
height: 1em;
width: 1em;
}
/**
* optional adjustment:
* font-size: if icons are too big
* vertical baseline offset
**/
.svg-adjust {
font-size: 0.75em;
position: relative;
bottom: -0.1em;
transition: 0.3s;
}
/* set size by viewbox if present */
.svg-inline[viewBox] {
width: auto;
}
.svg-inline-assets{
display:none
}
a:hover .svg-inline {
fill: green;
transform: scale(1.5);
margin-left: 0.5em;
margin-right: 0.5em;
}
/* example layout */
html {
font-family: "Segoe UI";
font-size: calc(1vw + 1vh /2);
line-height: 1.4em;
}
.layout {
width: 50%;
margin: 0 auto;
font-size: 1.5em;
line-height: 1.4em;
}
p {
margin: 0;
}
a {
text-decoration: none;
color: inherit;
border-bottom: 2px solid #aaa;
}
a .svg-inline {
fill: #aaa;
}
.button {
font-size: 1.333em;
line-height: 1em;
background-color: #aaa;
border: 2px solid #aaa;
color: #fff;
cursor: pointer;
margin-top: 1rem;
padding: 0.3em;
}
.button .svg-inline {
fill: #fff;
}
.input-range {
width: 100%;
}
<main class="layout">
<h3>Change font Size</h3>
<p>
<input class="input-range fontSize" type="range" value="0" min="-0.5" max="0.5" step="0.1">
</p>
<svg class="svg-inline-assets" viewBox="0 0 100 100">
<!-- every asset has it's own viewbox: this way we can place icons with different widths -->
<symbol id="fa-arrow-right-asset" viewBox="0 0 100 100">
<path d="M42.5,7.8l5-5c2.1-2.1,5.5-2.1,7.5,0c0,0,0,0,0,0l43.4,43.4c2.1,2.1,2.1,5.5,0,7.5c0,0,0,0,0,0L55,97.2c-2.1,2.1-5.5,2.1-7.5,0c0,0,0,0,0,0l-5-5c-2.1-2.1-2.1-5.5,0-7.6c0,0,0.1-0.1,0.1-0.1l26.9-25.6H5.4c-3,0-5.3-2.4-5.4-5.3c0,0,0,0,0,0v-7.1c0-3,2.4-5.3,5.3-5.4c0,0,0,0,0,0h64.1L42.6,15.5c-2.1-2-2.2-5.4-0.2-7.5C42.4,7.9,42.5,7.8,42.5,7.8z" />
</symbol>
<symbol id="fa-arrow-right-long-asset" viewBox="0 0 200 100">
<path d="M141.1,7.8l5-5c2.1-2.1,5.5-2.1,7.5,0c0,0,0,0,0,0L197,46.2c2.1,2.1,2.1,5.5,0,7.5c0,0,0,0,0,0l-43.4,43.4c-2.1,2.1-5.5,2.1-7.5,0c0,0,0,0,0,0l-5-5c-2.1-2.1-2.1-5.5,0-7.6c0,0,0.1-0.1,0.1-0.1l26.9-25.6H5.4c-3,0-5.3-2.4-5.4-5.3c0,0,0,0,0,0v-7.1c0-3,2.4-5.3,5.3-5.4c0,0,0,0,0,0h162.7l-26.9-25.6c-2.1-2-2.2-5.4-0.2-7.5C141,7.9,141,7.8,141.1,7.8z" />
</symbol>
<!-- this arrow has a x offset of 200: without it's own viewbox it would be cropped -->
<symbol id="fa-arrow-right-long-offset-asset" viewBox="200 0 200 100">
<path d="M341.1,7.8l5,-5c2.1,-2.1,5.5,-2.1,7.5,0c0,0,0,0,0,0l43.4,43.4c2.1,2.1,2.1,5.5,0,7.5c0,0,0,0,0,0l-43.4,43.4c-2.1,2.1,-5.5,2.1,-7.5,0c0,0,0,0,0,0l-5,-5c-2.1,-2.1,-2.1,-5.5,0,-7.6c0,0,0.1,-0.1,0.1,-0.1l26.9,-25.6h-162.7c-3,0,-5.3,-2.4,-5.4,-5.3c0,0,0,0,0,0v-7.1c0,-3,2.4,-5.3,5.3,-5.4c0,0,0,0,0,0h162.7l-26.9,-25.6c-2.1,-2,-2.2,-5.4,-0.2,-7.5c0.1,0,0.1,-0.1,0.2,-0.1z" />
</symbol>
<symbol id="fa-arrow-right-narrow-asset" viewBox="0 0 60 100">
<path d="M57.5,46.2L14.1,2.8c0,0,0,0,0,0c-2.1-2.1-5.5-2.1-7.5,0l-5,5c0,0-0.1,0.1-0.1,0.1c-2,2.1-1.9,5.5,0.2,7.5l37,34.5l-37,34.5c0,0-0.1,0.1-0.1,0.1c-2.1,2.1-2.1,5.5,0,7.6l5,5c0,0,0,0,0,0c2.1,2.1,5.5,2.1,7.5,0l43.4-43.4c0,0,0,0,0,0C59.6,51.7,59.6,48.3,57.5,46.2z" />
</symbol>
</svg>
<h2>Svg inlined icon</h2>
<p><svg class="svg-inline">
<use href="#fa-arrow-right-asset" />
</svg>No vertical adjustment. One morning, when
<svg class="svg-inline svg-adjust">
<use href="#fa-arrow-right-asset" />
</svg>
Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin. He lay on his armour-like back, and if he lifted his head a
<a href="#"><svg class="svg-inline svg-adjust" viewBox="0 0 200 100">
<use href="#fa-arrow-right-long-asset" />
</svg>
little he could see his brown belly</a>, slightly domed and divided by arches into stiff sections.
<svg class="svg-inline svg-adjust" viewBox="0 0 200 100">
<use href="#fa-arrow-right-long-offset-asset" />
</svg> Long arrow with offset.
</p>
<p>The bedding was hardly able to cover it and seemed ready to slide off any moment. His many legs, pitifully thin compared with
<svg class="svg-inline svg-adjust" viewBox="0 0 60 100">
<use href="#fa-arrow-right-narrow-asset" />
</svg> the size of the rest of him, waved about helplessly as he looked. "What's happened to me? " he thought. It wasn't a dream.
</p>
<p>
<button class="button" type="button">
<svg class="svg-inline svg-adjust" viewBox="0 0 60 100">
<use href="#fa-arrow-right-narrow-asset" />
</svg> Button
</button>
<button class="button" type="button">
<svg class="svg-inline svg-adjust">
<use href="#fa-arrow-right-asset" />
</svg>
</button>
<button class="button" type="button">
<svg class="svg-inline svg-adjust" viewBox="0 0 200 100">
<use href="#fa-arrow-right-long-asset" />
</svg>
</button>
</p>
</main>
You can try setting width and height for svg tag. Working link is here
add to svg transform="scale(1.7)" for zoon in
<svg transform="scale(1.7)" width="16px" height="24px" version="1" viewBox="0 0 700 700" xmlns="http://www.w3.org/2000/svg" >

Anchor hover with inline SVG and text

Not sure how to accomplish this, but I have an SVG inline with some text wrapper in an anchor tag. But the SVG isn't changing color when hovering over the anchor as a whole, just the text. Once you hover over the SVG, it will change color, but I'm wondering how get to to trigger the hover state as a whole.
CSS:
a, a svg {
color: #fff;
}
a:hover {
color: #111;
}
a svg:hover {
fill: #111;
}
HTML:
<a href="https://facebook.com/username" target="_blank">FACEBOOK
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="30px" height="30px" viewBox="0 0 30 30" enable-background="new 0 0 30 30" xml:space="preserve">
<path d="M17.252,11.106V8.65c0-0.922,0.611-1.138,1.041-1.138h2.643V3.459l-3.639-0.015
c-4.041,0-4.961,3.023-4.961,4.961v2.701H10v4.178h2.336v11.823h4.916V15.284h3.316l0.428-4.178H17.252z"/>
</svg>
</a>
I could have swore I've had this working somewhere else before not sure why it wouldn't work here.
Give the path an attribute fill="currentColor", and it will inherit the fill color from its parents.
a {
color: #fff;
}
a:hover {
color: #111;
}
<a href="https://facebook.com/username" target="_blank">FACEBOOK
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="30px" height="30px" viewBox="0 0 30 30" enable-background="new 0 0 30 30" xml:space="preserve">
<path fill="currentColor" d="M17.252,11.106V8.65c0-0.922,0.611-1.138,1.041-1.138h2.643V3.459l-3.639-0.015
c-4.041,0-4.961,3.023-4.961,4.961v2.701H10v4.178h2.336v11.823h4.916V15.284h3.316l0.428-4.178H17.252z"/>
</svg>
</a>
The fill color of your svg is showing by default #111 so you need to change the fill color of the svg normal state in your CSS. I don't know if you meant to have the text as white but you can obviously change that if you need to.
a, a svg {
color: #fff;
fill: #FF0000;
}
a:hover {
color: #111;
}
a:hover svg {
fill: #111;
}
<a href="https://facebook.com/username" target="_blank">FACEBOOK
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="30px" height="30px" viewBox="0 0 30 30" enable-background="new 0 0 30 30" xml:space="preserve">
<path d="M17.252,11.106V8.65c0-0.922,0.611-1.138,1.041-1.138h2.643V3.459l-3.639-0.015
c-4.041,0-4.961,3.023-4.961,4.961v2.701H10v4.178h2.336v11.823h4.916V15.284h3.316l0.428-4.178H17.252z"/>
</svg>
</a>

How to set a rotation point on a nested SVG Element

Recently, I decided to experiment and learn about CSS Transforms. Now, I decided to try and make a common mobile button using SVG and a few transforms.
What I'm trying to do is to make the mobile button rotate 90 degrees with a transform origin on the very center of the element.
Here is my code:
.mobileNav {
display: block;
transition: .5s;
}
.mobileNav:hover {
transform: rotate(90deg);
transform-origin: 50% 50%;
/*This is where the problem lies. How do I set the origin to the center of .mobileNav?? */
}
ul {
float: right;
margin: 15px 50px 0px 0px;
}
li {
display: inline-block;
transition: .5s;
}
<ul class="mobileNav">
<li>
<svg x="0px" y="0px" width="10" height="20">
<circle cx="5" cy="10" r="3" stroke-width="4" fill="#333" />
Sorry, your browser does not support inline SVG.
</svg>
</li>
<li>
<svg x="0px" y="0px" width="10" height="20">
<circle cx="5" cy="10" r="3" stroke-width="4" fill="#333" />
Sorry, your browser does not support inline SVG.
</svg>
</li>
<li>
<svg x="0px" y="0px" width="10" height="20">
<circle cx="5" cy="10" r="3" stroke-width="4" fill="#333" />
Sorry, your browser does not support inline SVG.
</svg>
</li>
</ul>
GOAL: To set the transform origin to the center of .mobileNav.
PROBLEM: I am unable to achieve this.
BROWSER: My browser is Firefox 44.0.2
ul has defaut padding or margin that needs a reset.
li and svg could be reset to inline-block.
Lets draw a border for debug to see where things stand.
vertical-aign + line-height will help to define an height to ul and will set childs at vertical middle.
body {
margin-top:50px;/* snippet wants this */
}
.mobileNav {
display: block;
transition: .5s;
border: solid;
padding: 0
}
.mobileNav:hover {
transform: rotate(90deg);
}
ul {
float: right;
margin: 15px 50px 0px 0px;
line-height: 1em;
}
li,
svg {
display: inline-block;
vertical-align: middle;
transition: .5s;
}
<ul class="mobileNav">
<li>
<svg x="0px" y="0px" width="10" height="20">
<circle cx="5" cy="10" r="3" stroke-width="4" fill="#333" />Sorry, your browser does not support inline SVG.
</svg>
</li>
<li>
<svg x="0px" y="0px" width="10" height="20">
<circle cx="5" cy="10" r="3" stroke-width="4" fill="#333" />Sorry, your browser does not support inline SVG.
</svg>
</li>
<li>
<svg x="0px" y="0px" width="10" height="20">
<circle cx="5" cy="10" r="3" stroke-width="4" fill="#333" />Sorry, your browser does not support inline SVG.
</svg>
</li>
</ul>
Your problem is the default padding. For added effect, you can also set the SVG and li's to not be display inline or inline-block. Then float them so the align vertically. That should make it not as janky.
body {padding: 3em;}
.mobileNav {
display: block;
transition: .5s;
padding: 0;
}
.mobileNav:hover {
transform: rotate(90deg);
transform-origin: 50% 50%;
/*This is where the problem lies. How do I set the origin to the center of .mobileNav?? */
}
ul {
float: right;
margin: 15px 50px 0px 0px;
}
li {
display: inline-block;
transition: .5s;
}
.mobileNav svg, .mobileNav li {
display:block;
float:left;
}
<ul class="mobileNav">
<li>
<svg x="0px" y="0px" width="10" height="20">
<circle cx="5" cy="10" r="3" stroke-width="4" fill="#333" />
Sorry, your browser does not support inline SVG.
</svg>
</li>
<li>
<svg x="0px" y="0px" width="10" height="20">
<circle cx="5" cy="10" r="3" stroke-width="4" fill="#333" />
Sorry, your browser does not support inline SVG.
</svg>
</li>
<li>
<svg x="0px" y="0px" width="10" height="20">
<circle cx="5" cy="10" r="3" stroke-width="4" fill="#333" />
Sorry, your browser does not support inline SVG.
</svg>
</li>
</ul>

class svg :hover css fill not working correctly [duplicate]

This question already has answers here:
How to modify the fill color of an SVG image when being served as background image?
(24 answers)
Closed 7 years ago.
How can I cause this svg to fill when I hover? I looked at a fair amount of documentation and tried several ways but was unsuccessfully.
Here is my html:
<a class="anchor-class" href="#"><svg class="svg-class"></svg></a>
And i have tried the following in my css
a svg:hover {
fill: #50c8e8;
}
as well as
.anchor-class svg:hover{
fill: #50c8e8;
}
and even
.svg-class :hover{
fill:#50c8e8;
}
What am I doing wrong? I should be able to accomplish this with css, right?
EDIT: It might help to note that this image is being used as a background image. a little more detail in the css below:
.svg-class {
background-repeat: no-repeat;
background-size: 20px 20px;
height: 20px;
width: 20px;
display: inline-block;
.background-image('path.svg')
}
EDIT 2: Here is the .svg code, not sure that it is important though
<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 100 100" style="enable-background:new 0 0 100 100;" xml:space="preserve">
<style type="text/css">
.st0{fill:#E4E4E4;}
</style>
<path id="XMLID_154_" class="st0" d="M85.5,15c-19.5-19.4-51-19.4-70.4,0c-19.5,19.4-19.5,51,0,70.4c19.5,19.5,51,19.4,70.4,0
C105,66,105,34.4,85.5,15z M49.5,9c5.3,0,9.5,4.3,9.5,9.5c0,5.3-4.3,9.6-9.5,9.6c-5.3,0-9.6-4.3-9.6-9.6C39.9,13.2,44.1,9,49.5,9z
M64.8,79.1c0,2-1,3-3,3H37.3c-2,0-3-1-3-3v-6.3c0-2,1-3,3-3h4.5V43.4h-4.6c-2,0-3-1-3-3v-6.3c0-2,1-3,3-3h17.2c2,0,3,1,3,3v35.7
h4.6c2,0,3,1,3,3V79.1z"/>
</svg>
UPDATE: with the svg code that you posted, you can do this behavior in this way.
Example:
a .svg-class:hover path {
fill: #50c8e8;
}
.svg-class {
height: 20px;
width: 20px;
display: inline-block;
}
<a class="anchor-class" href="#">
<svg class="svg-class" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 100 100" style="enable-background:new 0 0 100 100;" xml:space="preserve">
<style type="text/css">
.st0{fill:#E4E4E4;}
</style>
<path id="XMLID_154_" class="st0" d="M85.5,15c-19.5-19.4-51-19.4-70.4,0c-19.5,19.4-19.5,51,0,70.4c19.5,19.5,51,19.4,70.4,0
C105,66,105,34.4,85.5,15z M49.5,9c5.3,0,9.5,4.3,9.5,9.5c0,5.3-4.3,9.6-9.5,9.6c-5.3,0-9.6-4.3-9.6-9.6C39.9,13.2,44.1,9,49.5,9z
M64.8,79.1c0,2-1,3-3,3H37.3c-2,0-3-1-3-3v-6.3c0-2,1-3,3-3h4.5V43.4h-4.6c-2,0-3-1-3-3v-6.3c0-2,1-3,3-3h17.2c2,0,3,1,3,3v35.7
h4.6c2,0,3,1,3,3V79.1z"/>
</svg>
</a>