Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inline CSS for anchor tag and hover

Tags:

css

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> 
like image 227
John R Avatar asked Aug 13 '11 00:08

John R


People also ask

Can I use hover in inline CSS?

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.

How do I style an inline anchor tag?

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.

How do you write hover inline CSS react?

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.

How do you use hover in style tag?

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.


2 Answers

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!

like image 111
ninjascript Avatar answered Oct 08 '22 00:10

ninjascript


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> 
like image 30
Joseph Marikle Avatar answered Oct 07 '22 23:10

Joseph Marikle