How can I create a two-colored link that switches the colors when the mouse hovers over the text?
The result should behave like this:
Based on https://stackoverflow.com/a/4531233/11826257, I tried the solution below. But it only re-colors the word over which the mouse hovers.
<!DOCTYPE html>
<html>
<head>
<style>
span.red_to_blue{color:red;}
span.red_to_blue:hover{color:blue;}
span.blue_to_red{color:blue;}
span.blue_to_red:hover{color:red;}
</style>
</head>
<body>
<a href="#">
<span class="red_to_blue">Hello</span>
<span class="blue_to_red">World</span>
</a>
</body>
</html>
2
Answers
The comment from CBroe contains the solution: You can use a:hover followed by a CSS class selector. It is thus possible to define different behaviors for different classes. The classes can then be referred to in the html code, for example within a span element. The remodeled code looks like this:
Did you try putting
SPAN
withinSPAN
?