Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

Shon Levi
Shon Levi
6,036 Points

How to change img src="image.svg" (not inline svg) fill?

I want to make button with icon that I create in svg I have file of the icon.svg

My problem is that when I inline svg - it going out of my button (button is responsive and svg icon is something 500x500)

So I make img src="icon.svg" and it now getting to the 100% auto - responsive

BUT

I need to change the fill color of the svg when hovering the button - how can I change external file???

regular css not work for it - maybe something in js?

3 Answers

Shon Levi
Shon Levi
6,036 Points

my HTML

<img class="svg" src="icon.svg" alt="" />

my CSS

img.svg { fill: #b9c9d4; }

not working

Cindy Lea
Cindy Lea
Courses Plus Student 6,497 Points

I was thinking more in the lines of this: (you will need to customize)

#button1:hover {
  width: 200px; // in your case you would add code to change fill color
}