I don't know that there is any simple way to do this with css, but you can do this fairly easily with jquery.
<a href="#" class="random-color">Test link 1</a>
<a href="#" class="random-color">Test link 2</a>
<!-- source script for jquery -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
// Colors array with whatever colors you want
var colors = ['#ff8800','#ff00ff','#00ffcc'];
// This applies a random color to the link when you hover it
$('.random-color').mouseenter(function(){
$(this).css('color', colors[ Math.floor( Math.random() * colors.length ) ]);
});
// This function will return the color of the link to default when the mouse leaves
$('.random-color').mouseleave(function(){
$(this).css('color', '#0000ee');
});
</script>
You can see the working code here.
The links are assigned a class, in this case random-color, which is used to access it via the jquery selector $('.random-color')
. the .mouseenter
event triggers when your mouse is over the link, and then using $(this).css()
you can apply the styles you need.
Using the colors[ Math.floor( Math.random() * colors.length ) ]
, you assign it a random element from the colors array. You can also add, subtract, or alter any of the colors in the array.