Changing Text Colour On Hover

Hi,

In Elements, I am trying to create a card that contains an SVG, a heading and a piece of body text. I want each element of the card to change colour when the cursor hovers over the card. (ie. the card background changes from grey to green and the text and SVG change from black to white).

I can make the container background change on hover, but the SVG will only change when the cursor is over it and I cannot find a way to change the text on hover. (I think this is possible using a CSS class, but cannot find a worked example).

Is there a way to achieve this easily? Or even with difficulty?

Thanks in advance.

You can do this by changing the item shown in the image below.

Just change it from Self to Parent then when the hover is over the parent it will also cause the hover effect for the SVG to appear.

Terrific - thank you. Is there an equivalent for text?

Unfortunately, there is not currently. It is something I have requested before as it would be very useful.

Hi @BrettHannam

As @handshaper says, there is no built in way to do this at the moment. However, you can use a couple of tailwind classes on the Text component to achieve this.

I’ve created an example project, which you can open in Elements
. In the project I’m using a Flex with an SVG and Text inside.

The tailwind classes are: group-hover/flex:text-green-700 transition-colors duration-500

The magic is in the group-hover/flex modifier. Every built in component has a named “group” class applied, so you can target it in this way. If you’re not sure how this works, we can get @elementsbot to explain how group modifies in Tailwind works :slight_smile:

2 Likes

That’s really helpful. Thank you very much for going to so much trouble in your reply.

1 Like

This is good to know. I will start using this until we have support built into Elements.