Answer the question
In order to leave comments, you need to log in
How to replace svg fill on hover?
I can't find a solution to this problem! Svg is set via background-image, you need to change the fill color on hover.
There are 2 conditions:
1) the path to the svg must be only through background-image, the variant with through html, unfortunately, is not suitable.
2) There is an option - to change on hover to another image, with the desired fill color, but there is a link on the block, and when you click, instead of replacing the image, an empty space appears. This is especially noticeable on tablets.
I ask everyone who knows the solution to help. Thanks in advance!
Answer the question
In order to leave comments, you need to log in
1) It won't work. Through background-image - definitely nothing. It doesn't even have animations.
2) Here you can think.
.svg {
background-image: url(svg1.svg);
}
.svg:hover {
background-image: url(svg1_hover.svg);
}
so that there is no call to the server with :hover, you can do this
.svg {
background-image: url('data:image/svg+xml;utf8,<svg ...><path fill="#FFFBBB" ... /></path></svg>');
}
.svg:hover {
background-image: url('data:image/svg+xml;utf8,<svg ...><path fill="#DDDAAA" ... /></path></svg>');
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question