In my application, I can't get the a:hover
css style to work when my anchor tag doesn't have an href attribute.
Is there any reason for this?
In my application, I can't get the a:hover
css style to work when my anchor tag doesn't have an href attribute.
Is there any reason for this?
Might not be the answer, but a:hover must occur after a:link and a:visited to be effective.
See W3Schools
IE doesn't support a:hover in a tag without href. You can use href="#" or href="Javascript:void(0);" however this last option probably won't work on IE6 either.
Or use Javascript mouseover/mouseout.
Which browser are you using? This may be a quirk - certainly href
isn't required I don't think, i.e. when using the legacy <a name>
method to create links within the document.
The W3C CSS 2.0 specification for the :hover
selector doesn't mention anything about requiring an href attribute.
I suspect this is something implementation-specific, most likely IE being silly. If I remember right, Microsoft invented the :hover
selector before it became part of the CSS standard, and it originally only applied to anchors. So yeah, it's probably a quirk of IE(6).
A hacky fix for IE6 (all IE?) might be to use href="#"
which just points to the current page (and thus does nothing).
Hover is intended for links. Without the HREF the tag is simply an anchor.
In other words...
<a name="target"></a>
is an ANCHOR within a page that...
<a href="#target">go there</a>
would be a LINK to.
Since ANCHORs don't have visual representation on a page.. a :hover would be useless.
Try adding DOCTYPE. IE tends to ignore certain directives without it. Specifically, :hover on an anchor tag fails without HREF in IE8 but works when the XHTML Transitional DOCTYPE is included.