Change html svg cricle fill css when clicking on

I use the following svg figure as a button:

<svg id="button-more-people" style="width: 60px; height: 60px;">
    <circle cx="30" cy="30" r="30" fill="#F44336" id="circle-button-more-people"/>
    <text fill="#ffffff" font-size="45" x="11" y="44" font-family="Verdana">+</text>
</svg>

When the mouse hangs over the circle, I scale the button up through css:

#button {
    transition: 0.3s ease;
}

#button:hover {
    transform: scale(1.2);   
}

What I can not achieve is to change the color of the buttons when pressed. I tried the following, to no avail:

#button:active ~ circle {
    fill: #D50000;
}

I would prefer if I used a javascript-smaller solution that I could use.

Thanks for any help in advance!

+4
source share
1 answer

The problem is the selector used for fill:

#button:active ~ circle {

General Sibling Combinator, <circle>, , button, , <circle>, button

:

#button:active circle {

:

#button:active > circle {

:

#button-more-people {
  transition: 0.3s ease;
}

#button-more-people:hover {
  transform: scale(1.2);
}

#button-more-people:active circle {
  fill: #D50000;
}
<svg id="button-more-people" style="width: 60px; height: 60px;">
    <circle cx="30" cy="30" r="30" fill="#F44336" id="circle-button-more-people"/>
    <text fill="#ffffff" font-size="45" x="11" y="44" font-family="Verdana">+</text>
</svg>
Hide result
+4

Source: https://habr.com/ru/post/1685781/


All Articles