Search code examples
csssvgsmil

SVG set attribute fill not working


I want my svg to change its fill when the button it is inside of is hovered over.

<set attributeName="fill" to="#AEAEAE" begin="button.mouseover" end="button.mouseout"/>

I thought this would work but it is keeping its original fill of #FF702A

Can anyone help on this?

/////Edit//////

I refactored it to make it simpler. Unless I'm missing some major concept this should be possible with just css?

Here is the html-

 <div id="button">show svg onhover
     <svg id="play" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" x="0px" y="0px" width="42px" height="62px" viewBox="0 0 24 32" style="enable-background:new 0 0 24 32;" xml:space="preserve" xmlns:xml="http://www.w3.org/XML/1998/namespace">
    <g id="Layer_1">
    </g>
    <g id="play">
      <polygon points="0,0 24,16 0,32  "/>      
    </g>
   </svg>
  </div>

and here is the relevant css

#button {

height: 75px;
width: 275px;
font-size: 25px;
text-align: center;
background: #FF702A;
border-radius: 10px;
padding-top: 40px;
margin-top: 70px;
margin-left: 150px;
opacity: 0.7;
letter-spacing: 1px;
font-variant: small-caps;
color: #EEEEEE; 

}

#button:hover {
opacity: 1.0;
font-size: .01em;

}

#play{
position: absolute;
margin-left: -90px;
margin-top: -10px;
visibility: hidden;

}

#play:hover {
visibility: visible;

}

It's a hack to hide the text on hover but why isn't visibility working onhover for the svg? Sorry to take it a different direction from the original question but hopefully this clears things up a bit. Looking to accomplish with pure css..


Solution

  • You could also just do this with CSS:

    #button { fill: #FF702A; }
    #button:hover { fill: #AEAEAE; }
    

    You'll have to add the element with id="button" (and its children if any) to the question if you want an answer to why it isn't working.