Forum Moderators: not2easy

Message Too Old, No Replies

Inline CSS for links works in IE but not in Firefox

         

penstaar

5:20 pm on Dec 12, 2006 (gmt 0)

10+ Year Member



Hi there,

Firstly, I know inline styles are bad bad bad, but feel I have to use it in this case.

I found this code on another forum to style one instance of a link. It works fine in IE/Windows but not in Firefox/Safari on a Mac. That is, the link and hover state appear white in IE, but still appear red (the default link style) in Firefox and Safari on the Mac.

Does anyone see anything wrong with it?

<a href="http://www.mylinkhere.com" style="{color:white}; :visited{color:white} :hover{color:white}">Link Text</a>

Also, the css validator doesn't seem to work for inline css, but if one exists that anyone knows of, please let me know.

Thanks and Happy Holidays!

bedlam

5:37 pm on Dec 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Does anyone see anything wrong with it?

<a href="http://www.mylinkhere.com" style="{color:white}; :visited{color:white} :hover{color:white}">Link Text</a>

Yes:

  • The syntax you've used makes no sense in this context ('{' and '}' are not permitted here),
  • You can't define pseudo-classes (like e.g. :hover) in inline styles.

If you want to have some links styled differently than others, you're going to need to use a class on the links itself, or a class or id on the link's container. For example, you could do this:

HTML

<a href="http://www.mylinkhere.com" class="foo">Link Text</a>

CSS

a.foo,
a.foo:visited,
a.foo:hover { color:#fff; }

...or this:

HTML

<ul id="foo">
<li><a href="http://www.mylinkhere.com" class="foo">Link Text</a></li>
<li><a href="http://www.mylinkhere.com" class="foo">Link Text</a></li>
</ul>

CSS

#foo a,
#foo a:visited,
#foo a:hover { color:#fff; }

-b

penstaar

6:19 pm on Dec 12, 2006 (gmt 0)

10+ Year Member



Thanks for the response, but I don't have access to the external style sheets or the head of the document, which is why I opted for inline...

So, you are saying I cannot have an inline hover period? Darn!

Maybe I can get by with just the off state being white, so should I just use style="color:white" inside my href tag for that?

ie <a href="mylink.com" style="color:white">link</a>

Thanks for your help.

penstaar

6:24 pm on Dec 12, 2006 (gmt 0)

10+ Year Member



Actually I just tested my last option and it seemed to work to make the hover and visited states white as well...

penders

8:57 pm on Dec 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks for the response, but I don't have access to the external style sheets or the head of the document, which is why I opted for inline...

So, you are saying I cannot have an inline hover period? Darn!

If you just want to change the colour of your link, with default/hover/visited colours all being the same, then yes, you can simply set:

style="color:white;"

If you want to have a hover/rollover effect where the link changes colour as you move over it, then... with no access to a <style> section... you need to do it the 'old way' with inline events that call a small bit of JavaScript that changes the style/colour of the element:

<a href="#" style="color:#090;" onmouseover="this.style.color='#f00';" onmouseout="this.style.color='#090';">Link Text</a>

The link starts off dark green (#090), changes to red (#f00) as you 'hover'/onmouseover the link and back to green again as you move away/onmouseout.

This will work OK in FF and IE.