Weird IE7 Hover Bug/Problem
This is my little CSS style:
#languages_menu
{
background: url('/images/langs.png') repeat-y;
bottom: 40px;
font-size: 0.9em;
right: 10px;
position: absolute;
width: 90px;
}
#languages_menu ul, #languages_menu ul li
{
list-style: none;
}
#languages_menu ul li a
{
cursor: pointer;
display: block;
line-height: 22px;
margin-left: 10px;
text-decoration: none;
width: 80px;
}
#languages_menu ul li a:hover
{
background-color: #AEBDD2;
color: #F00;
}
#languages_menu ul li a span.flag
{
float: left;
margin: 3px 5px 0 3px;
}
And this is my HTML code (copied from Developer Toolbar, so don't worry, it's valid):
<!-- DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" -->
...
<DIV id=languages_menu><DIV class=topimg></DIV>
<DIV>
<UL>
<LI><A class=en><SPAN class=flag></SPAN><SPAN class=name>English</SPAN></A></LI>
<LI><A class=fr><SPAN class=flag></SPAN><SPAN class=name>Français</SPAN></A></LI>
...
</UL>
</DIV>
</DIV>
In IE8, IE8Compatibility and IE9, and in every other browser, :HOVER is working like a charm. But if I switch to IE7 or lesser, the anchor is not changing anymore on mouse over.
The worst thing is that I have other similar codes on the same page and they are still working after I switch to IE7, like the following one:
#navigation
{
height: 22px;
position: relative;
width: 100%;
}
#navigation ul
{
float: left;
left: 50%;
}
#navigation ul, #navigation ul li
{
float: left;
list-style: none;
position: relative;
}
#navigation ul li
{
right: 50%;
}
#navigation ul li a
{
color: #889DBF;
display: block;
line-height: 22px;
padding-left: 20px;
text-decoration: none;
}
#navigation ul li a b
{
display: block;
padding-right: 21px;
}
#navigation ul li.current a, #navigation ul li a:hover
{
background: url('/images/navigation-left.png') no-repeat;
color: #111B35;
}
#navigation ul li.current a b, #navigation ul li a:hover b
{
background: url('/images/navigation-right.png') no-repeat 100% 0;
color: #111B35;
}
<DIV id=navigation>
<UL>
开发者_运维知识库<LI class=current><A href="#login"><B id=text_menu_login>Accedi</B></A></LI>
<LI><A href="#register"><B id=text_menu_register>Registrati</B></A></LI>
...
</UL>
</DIV>
Anyone knows why this is happening and how to fix it?
[EDIT] I just found a fix for this bug. If i replace:
#languages_menu ul li a:hover
With:
#languages_menu ul li:hover a
The menu works great even with IE lesser than 8. But I don't think it's a good solution for cross-browser compatibility because :hover pseudo-class can not be used in IE lesser than 7.
MANY MANY THANKS ERIC!
you need to add href to your anchor, a:hover is not picked up by IE7 otherwise:
<A class=en href="#">
another trick is to add empty rule in your css:
#languages_menu ul li a:hover {
/* all your hover rules go here */
}
#languages_menu ul li:hover a {
/* keep this empty, triggers a:hover on IE7 */
}
Add a default background-color to your non-hovered link (just use white).
精彩评论