Help: How to: Flip element on hover, keep end state, then reverse on next hover

What the title says ☝️ I have tried to make a pen, I don't understand why it does not work: https://codepen.io/ingvild/pen/OJKyzBy I think this is a pretty "fair" request, and it should be easier to solve in CSS, so anyone wants to contribute? I want to solve this only using CSS. I have tried a variety of alternatives, no one leading to success πŸ™ƒ I added a video showing how on hover I don't want the icon to flip back when I unhover, but to stay in the flipped position, then on next hover, flip back to it's original state. Desired behavior: 1. Hover: scaleX ➑️ -1 2. Unhovers: Keeps scaleX -1 3. Hovers 2nd time: scaleX ➑️ 1 4. Unhovers: Keeps scaleX 1 5. Repeat from 1.
8 Replies
Chris Bolson
Chris Bolsonβ€’3mo ago
I’m pretty sure that you won’t be able to do that with CSS alone.
Jochem
Jochemβ€’3mo ago
yeah, I'm pretty sure you'd have to track state somehow, and I don't think you can do that in CSS
ingvildforseth
ingvildforsethOPβ€’3mo ago
Ah, nice to know so I can stop my fruitless attempts πŸ˜… Thanks!
Chris Bolson
Chris Bolsonβ€’3mo ago
I did have a go with @property but, as Jochem says, you need to track the state. If it were on click you could use a checkbox but on hover I can't think of any way to do it.
ingvildforseth
ingvildforsethOPβ€’3mo ago
Me too, tried @property, thinking that would help me both with 1) giving it an initial state and 2) allowing animation of the prop, but yeah, no success so far 😁 Thanks for making a go at it πŸ‘
ἔρως
ἔρως‒3mo ago
this isnt possible with pure css i tried this as well css variables work like css properties and not like variables in other languages once the hover reverts the css variable is no longer being set what is possible to do is to swap the button https://medium.com/@alexc73/state-in-css-ac57a1ebde09
ingvildforseth
ingvildforsethOPβ€’3mo ago
Ah, thanks! πŸ˜€ I only have the possibility to change the CSS, not add an extra element as the tutorial shows, but then I know an alternative at least πŸ™Œ
ἔρως
ἔρως‒3mo ago
you're welcome.
Want results from more Discord servers?
Add your server