kaht, thanks for pointing out the typo - I hadn't spotted it. I was going to sit this one out, but I'll come back just once more, from first principles this time...
I think most people know how to make a link change colour when the mouse is over it:
Now, what if you want to get the same effect for people who use the keyboard to navigate? If you press the [[]tab] key, each link on the page in turn is given the "focus". CSS defines a pseudo-class for this too:
But there's a problem here. Internet Explorer doesn't recognise [tt]a:focus[/tt], so users of that browser won't see the effect when using the keyboard. Don't worry though, it applies a different pseudo class for the link with the focus:
So we can define a CSS rule that will colour the link that currently has the user's attention, (almost) whatever browser they're using:
Code:
a:hover,a:focus,a:active { color:red }
But there's another problem [tt]a:active[/tt] has a different meaning according to
the spec:
The :active pseudo-class applies while an element is being activated by the user. For example, between the times the user presses the mouse button and releases it.
What if you want it to change to a
different colour when it's being clicked? According to the spec, you should be able to do this:
Code:
a:hover,a:focus { color:red }
a:active { color:green }
but as has already been noted, IE will apply the :active colour to whatever link has the focus. We need to add an IE-specific hack to put it back on the straight-and-narrow:
Code:
a:hover,a:focus { color:red }
a:active { color:green }
* html a:active { color:red } /* only IE will apply this */
But how do we keep all browsers' behaviour the same, and get IE to apply a colour just when the link's activated? Simple answer: we can't (well, not just with CSS anyway). IE doesn't have a pseudo-class which identifies such a status, so there's no way to write a rule for it that IE will apply.
You can dumb down the other browsers not to exhibit any special [tt]:active[/tt] behaviour (see my 4th example above), or you can miss out the IE hack and live with the fact that IE will apply the [tt]:active[/tt] rule to any link with the focus (it can look approximately the same to mouse users anyway). Alternatively, you can leave the hack in, so the [tt]:active[/tt] behaviour is a bonus that will only be seen by users of modern browsers - after all, getting pages that look
better is one reason people upgrade.
If you
have to get true [tt]:active[/tt] behaviour in IE, you're going to have to do it with Javascript. A slick way to do so is to use the "IE7" script available at
which actually fixes many of IE's CSS rendering bugs, including [tt]:active[/tt].
-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd