I'm under the impression that changing an anchor tag on hover can be done like this:
a:hover {background: #FFDD00;}
a:hover {color: #AAAAAA;}
Correct me if I'm wrong.
Now, for some convoluted reason, I can't put that code in a style sheet, I have to put it in the actual HTML. How would I do that?
<a href="..." style="___???___">...</a>
Short answer: you can't. Long answer: you shouldn't. Give it a class name or an id and use stylesheets to apply the style. :hover is a pseudo-selector and, for CSS, only has meaning within the style sheet.
Inline style methodAdd the style attribute directly to the anchor tag and specify the color property through the style attribute, then assign a color value.
Set the onMouseEnter and onMouseLeave props on the element. When the user hovers over or out of the element, update a state variable. Conditionally set inline styles on the element.
The :hover selector is used to select elements when you mouse over them. Tip: The :hover selector can be used on all elements, not only on links. Tip: Use the :link selector to style links to unvisited pages, the :visited selector to style links to visited pages, and the :active selector to style the active link.
If you can't toss your hover CSS into a tag, then the best way to handle this is going to be JavaScript. I wouldn't ordinarily call this a good approach, but it sounds like your hands are tied here.
<a href="..."
onmouseover="this.style.backgroundColor='#ffdd00';this.style.color='#aaaaaa'"
onmouseout="this.style.backgroundColor='transparent';this.style.color='inherit'">
...
</a>
Hope that works for you!
I'm pretty sure you can't apply psudo-classes inline, but you can do this with javascript inline.
e.g.
<a href="..." onmouseover="this.style.color = 'red'" onmouseout="this.style.color = 'black'">...</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With