0

Hello I would like to know how I can select the SVG inside span and change it's color on hover.

My svg is called from another style inside span:

<a href="#"><div><span class=icon over"></span></div></a>

What I am trying to do is something like this:

a:hover > div > span { fill: #fff; }

But it is not working on the SVG. on the actual span it is working with other property.

So the question is how I can change the color of the SVG which is called with another style which contains svg inside the span element.

SVG Code:

.icon{

background: url(../img/sprite.view.svg) no-repeat;
    display: inline-block;
    text-indent: -9000px;
    white-space: nowrap;

}

.over {
    background-position: 80.45977011494253% 26.016260162601625%;
    width: 32px;
    height: 32px;
}
John Siniger
  • 875
  • 2
  • 16
  • 39

1 Answers1

2

The reason to as why it's not working is because you can't change any colors when importing the SVG through an img tag, object tag or as a background of an element.

In order to manipulate an SVG with CSS it must be inline, inline as in:

<a href="#">
  <div class="svg-container">
    <svg></svg>
  </div>
</a>

Change your markup to what I've done above, with the entire SVG file inside the div, then apply the CSS like this:

.svg-container {

  > svg {
    fill: #fff;
    stroke: #000;
  }
}

As someone pointed out you can, however, change an object tag with Javascript should you need to use that instead of an inline SVG, should the SVG be really big.

Chrillewoodz
  • 27,055
  • 21
  • 92
  • 175