Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

:active css selector not working for IE8 and IE9

Here's my site. This is the last problem of a series of cross-browser discrepancies I've experienced and solved thanks to the community.

Basically, in Internet Explorer 8 and Internet Explorer 9 the :active styles are not applied to the menu. It should turn darker when pressed. Please let me know why and how to fix. Thanks in advance.

like image 952
UrBestFriend Avatar asked Apr 08 '11 10:04

UrBestFriend


People also ask

What is IE6 and IE8?

IE6 (in non-quirks mode): You write CSS for the IE6 limitations (hacks upon hacks) and sleep poorly. IE8 (in IE8/non-quirks mode): You write CSS which is [generally] compatible with other modern browsers and have happier dreams :p~ – user166390.

What is CSS active selector?

The :active selector is used to select and style the active link. A link becomes active when you click on it. Tip: The :active selector can be used on all elements, not only links.

How do I get CSS selector in IE?

Simply right click and click Inspect Element. This will bring up the CSS selectors for that element.

Should I support IE8?

So what should you do? Even if a relevant number of your users still use legacy IE browsers, do not support them. If your site breaks in IE10, IE9 or IE8, let it break and force users to look for safer alternatives.


1 Answers

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. See W3 documentation.

But you are applying your :active selector to your <li> element, which cannot have an active state since it never really gets activated - only hovered. You should apply :active state to <a> <- True for IE 6.

UPDATE: Here's a test sample at jsFiddle as you can see it works ok on <a> element but not ok on <li>

Interesting info I found here

The :active pseudo-class applies while a link is being selected by the user.

CSS1 was a little ambiguous on this behavior: "An 'active' link is one that is currently being selected (e.g. by a mouse button press) by the reader." Also, in CSS1, :active was mutually exclusive from :link and :visited. (And there was no :hover pseudo-class.)

CSS2 changed things so that rules for :active can apply at the same time as :visited or :link. And the behavior was explained a little better: "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."

IMO, FF et al comply with CSS2 better than IE. But since a link is supposed to load a new page, IE could legitimately say the link is still "active" while the new page is loading, which is what happens.

You can see a similar counter-intuitive behavior in FF by clicking the link, but moving your mouse off of the link while holding the mouse-button down. The link is not activated (a new page is not loaded), but the link remains in the :active state. On the other hand, Chrome and Opera de-activate the link, but at different times; Chrome as soon as the mouse leaves the link area, Opera not till the mouse button is released. IE behaves the same as FF in this example. (Hit enter after dragging your mouse off the link, and you will see more differences in behavior.)

I would not call any of these differences "bugs", because of ambiguities in the spec.

The only work-around I can offer is to accept that you can't control every aspect of browser behavior. Users of different browsers have differing expectations of behavior, and if you start messing with user expectation, you're on the wrong path.

like image 84
easwee Avatar answered Oct 18 '22 04:10

easwee