In this solution, I've doubled the text so the colored link can be below the span
and the clickable clone is rendered transparently atop it. Therefore, you see the colored link below the colored strikethrough line but you can still click it.
div {
font: bold 2em serif;
width:98%;
}
div.over {
position: absolute;
}
div.over span {
background:
linear-gradient(90deg, red, yellow, green, blue, magenta) no-repeat
0 60% / var(--s,0%) .1em,
transparent;
transition: background-size .4s ease;
}
div.over span:hover {
--s: 100%;
}
div.under {
position: relative;
z-index: -1;
}
div.over :is(span, span *) {
color:transparent;
}
<div class="over"><span>
<a href="#">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</a> At vero eos et accusam et justo duo dolores et ea rebum.
</span></div>
<div class="under"><span>
<a href="#">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</a> At vero eos et accusam et justo duo dolores et ea rebum.
</span></div>
This is made possible with containing <div>
elements using varying z-index
values. This lets us put elements above or below others. Everything defaults to zero, so I've put the colored link below zero and left the clickable link at the default depth. z-index
requires position:relative
(keep things where they are) or position:absolute
(make the element independent of its parents, render things around it as if it does not exist). It shouldn't matter that I chose the "over" copy to be absolute and the "under" copy to be relative, but the first must be absolute (to not affect the flow) and the second must be relative (to keep the flow correct).
There's a little oddity in which the absolute <div>
doesn't wrap the same way, but I solved that by forcing them both to width:98%
. A static value would be more reliable.
I initially misread your request as wanting a rainbow of colors for the strike-through effect, which is as simple as changing the parameters in the linear-gradient()
function. It's pretty, so I kept that. You can revert it by going back to linear-gradient(red 0 0)
.
You'll also notice that I removed a bunch of unnecessary CSS cues (color and background-clip). If that breaks things, put them back. Finally, I increased the font to be larger and bolder so you can more clearly see what's on top of what.