Good writeup by Katherine Kato of several techniques on how to change the color of a link on hover, animated
Let’s create a pure CSS effect that changes the color of a text link on hover… but slide that new color in instead of simply swapping colors.
There are four different techniques we can use to do this. Let’s look at those while being mindful of important things, like accessibility, performance, and browser support in mind.
When looking only at the code, I’m more a fan of the background-clip: text technique as it does not require you to duplicate the text into a data-* attribute. It does however has some nasty side-effects such as no longer displaying text-decorations and shadows.
If we only had something like content: text-content; in CSS, then we could remove the data-* content duplication requirement.
Internally it looks like this:
Note that the hitareas are made triangular using CSS Clipping, and not using the for this typically used CSS border-fiddling.
Here’s a Pen of the final markup for you to play with:
Sidenote/Related: The General Sibling Selector – just like any other Combinator such as the Adjacent Sibling Selector (+) for that matter – is a CSS Selector that’s very powerful and should be used more often. Here’s why: