I have an SVG with multiple lines that are different colors, and I want to change the colors on hover:
For other SVGs, I’ve changed it so fill=“currentcolor” and used Webflow’s typography to change them, but since this one has different colors, I want to change it within the custom code if that’s possible.
I’ve tried putting style=“svg:hover { fill: #000000;};” which I saw in another forum post, but that didn’t work…
Is there a way to do this?
I actually cannot include a read-only link for the website because my client is very particular about sharing.
I am sorry about the answer from the other forum you have received but :hover is a psuedo-element that has no meaning in inline CSS but is made to be used within a stylesheet.
I would recommend giving your svg a class, like <svg class="rect-svg" width="35px"... and then go into your Page Settings, scroll to the bottom section where you have option of adding custom code in the head section and include this code or use a custom HTML embed in your page above your svg element.
<style>
.rect-svg:hover {
fill: red;
}
</style>
What this would do for you is, when you hover with your mouse over the SVG with the class rect-svg, it will turn red.
For some reason, I’m still struggling to get it to work…
I tried it in the <head> section of the page and the website; and I tried putting it in the same HTML embed with the SVG.
I am sorry to hear that @eark, I did do a mistake in my previous code where I tried commenting within the css line, I have removed that now!
Also a quick note, you have to publish the site to a staging area, like webflow.io because custom codes do not get executed in the preview mode, they have to be published for you to see the code being implemented.
If you put your custom CSS in an HTML Embed element between <style> tags you’ll be able to see the effect live in the Designer
This can help you debug more quickly and once you get it working you can move that code over to the Page Settings (or Project Settings if it’s an element that appears on every page on the project).
I’m s t i l l struggling, if you wouldn’t mind taking a quick look at this code to see if I have this correct I would appreciate it very much, because it seems like it should be working…
That basically means: everytime x-svg is hovered, apply fill red to all the g tags that are a descendant of it AND do the same for all the path tags that are a descendant of it.
This code basically means: all g and path tags that are somewhere within the x-svg class should always inherit the current color of their most senior parent that has a color set. The important tag is there so that the browser ignores the inline style of those elements.