You can’t change the fill
via :hover
in the <style>
because it is already defined via style inline:
<path style="fill:#ffffff;stroke-width:1.95499432"...
To the :hover
work in the <style>
you must define the fill
in the <style>
, and can also use to define the stroke-width
, and remove the style
of the element:
Element without style:
<path d="m 409.51823,171.04465 c -1.61287,-0.34827 -8.87078,-1.19599 -16.1287,-1.88382 l -13.19621,-1.2506 v -25.25932 -25.25932 l 10.26372,0.0148 c 9.75768,0.014 34.79672,3.33913 36.27473,4.81715 0.64735,0.64736 -6.48667,38.8851 -8.67303,46.48669 -0.95153,3.30828 -2.31046,3.67973 -8.54051,2.33446 z"
id="d1s1"
inkscape:connector-curvature="0"
transform="matrix(0.26458333,0,0,0.26458333,4.9999997,48.5)"
inkscape:label="d1s1" />
CSS for the #d1s1:
<style>
#d1s1 {
fill:#ffffff;
stroke-width:1.95499432;
transition: fill 2s;
}
#d1s1:hover {
fill: #ffff00;
}
</style>
The ideal is to apply to path
(since everyone is path
) and not every id
, soon would be:
path {
fill:#ffffff;
stroke-width:1.95499432;
transition: fill 2s;
}
path:hover {
fill: #ffff00;
}
To change the color on click, create color classes and add via Javascript. For example, create a class for the green color:
.verde{
fill: #090;
}
Add a dataset cor
with the class name in path
according to the color you want it to be clicked on:
<path data-cor="verde" d="m 409.51823,171.04465 c -1.61287,-0.34827 -8.87078,-1.19599 -16.1287,-1.88382 l -13.19621,-1.2506 v -25.25932 -25.25932 l 10.26372,0.0148 c 9.75768,0.014 34.79672,3.33913 36.27473,4.81715 0.64735,0.64736 -6.48667,38.8851 -8.67303,46.48669 -0.95153,3.30828 -2.31046,3.67973 -8.54051,2.33446 z"
id="d1s1"
inkscape:connector-curvature="0"
transform="matrix(0.26458333,0,0,0.26458333,4.9999997,48.5)"
inkscape:label="d1s1" />
And create in Javascript create an event click for each path
which will apply the class according to the color of the dataset cor
of the clicked element:
<script>
var paths = document.querySelectorAll("path");
for(var x=0; x<paths.length; x++){
paths[x].addEventListener("click", function(){
this.classList.add(this.dataset.cor);
});
}
</script>
About Transition not working I answered below, about changing the color in the click this answer may help you, but with jQuery or JS you can in the event of the click put or take the color https://answall.com/questions/286686/mudar-a-cor-de-um-svg-por-um-bot%C3%A3o/286696#286696
– hugocsl