How to Fix IE7 Submenu Hover Problem
July 19th, 2010 by
Internet Explorer 7, among many other drawbacks, does not know what :hover in CSS means, so drop down menus may not work well in IE7 when using :hover.
Obviously, this defect happens in IE6 as well, however, since this blog doesn’t support IE6, I will only relate to the problem as it appears in IE7.
Some of you may prefer to build drop down menus using Javascript to begin with, however, I always recommend using CSS over javascript, unless you need some animation effects (because CSS renders faster then JS and it does not require the browser to have javascript turned on).
The classic CSS :hover syntax for drop down menus looks like this:
#menu li ul{display:none}/*all submenus are hidden*/
#menu li:hover ul{display:block}/*a submenu appears once the user hovers over the parent menu item*/This will work in all browsers except IE7 and below. What happens in IE7 is, that the submenu appears just as long as the mouse hovers over the parent menu item. So once you move the cursor downwards over the submenu, the submenu simply disappears.
Check out this demo page using Internet Explorer 7 (if you only have IE8 installed, simply click on the quirks mode button (near the refresh button)).
In the demo page, I wrote a simple script that toggles the IE7 hover fix by clicking the button.
The solution is to set a one pixel transparent background image (in .png format) to all submenu UL tags:
.submenu{background:url("images/transparent-image.png")}You may have read in other tutorials that a background color can do the trick, however, you can see in my demo page that the submenus have rounded corners at the bottom, and therefore, a background image to the submenu UL tags will override those round corners and they will not be rounded corners any longer.
An additional solution I have read about is the proper declaration of DOCTYPE to be strict in order to enable IE7 full css support (like discussed here), however, as you can see in the demo page, it already has such a declaration and still does not solve the hover problem.
Additional resources
- CSS Hover Submenus Disappear in IE
- Submenu disappears on mouseover in IE 6
- Creating submenu with css in IE
- CSS Dropdown Menu in IE7

An Update After So Long…
thanks for the tips, will try to add it on my future projects…
Thanks Aafrin. I wasn’t able to update for a month since I had a really busy time at work. But these days I’m trying to find more time to post frequently.
Omer,
Thanks for sharing this info. I try and make my site compatible with all browsers, but IE makes it hard to do this. I usually try do alternative coding for things I know I don’t work with IE. Things always tend to look funny with IE… I really dislike IE.
You are among people who think the same, James
99% of web developers hate IE, especially the older versions.
IE usually requires extra working hours to tweak for compatibility.
Thanks for very nice tip. I use this now. It’s interesting and it works when the image doesnt exist.
Thanks, t.h. which image are you referring to? the transparent png background?
Hi, yes I use this css line in simple JS code:
…
$(this).hover(function() {
$(‘#crumb div’).css(‘background’,'url(non-exist-transparent-image.png)’);
},
…
It works perfect… I have had problem only with IE7
Please forgive my newbie questions — can you please tell me where exactly I insert .submenu{background:url(“images/transparent-image.png”)}? In the custom.css file? Do you actually use the quotes? Do you actually use url? Thanks, and again, I apologize for the novice questions.
Howard, your syntax is correct although the quotes are not necessary. you should place this code in your theme style.css file.
In addition, make sure that the url you enter is the correct one.
Sound great, t.h. I’m glad you solved the problem.
FYI, I’m pretty sure that
background:url(“images/transparent-image.png”) no-repeat;
also works
That’s exactly the solution I presented here, yitwail.
Thank you. This rollover problem in IE7 has been driving me crazy for hours. Brilliant.
You’re welcome, Carmel. I;m glad I could help
not exactly the same, Omer. You left out the no-repeat. Without it, maybe the browser tiles the one pixel gif over the entire background.
I haven’t tested it yet, but thanks for the tip
Really nice job!
But it seems not to work when the submenu is positioned by absolute. Is this my fault?
Hendrik, actually the submenu is absolute in my demo page as well. When you say it doesn’t work you mean the menu disappeared completely or only after hover?
Thank you very much for this easy way of dealing with the IE 6&7 abnormalties
I can confirm what t.h. wrote earlier in this thread – the solution seems to work as long as you have a url in the css, whether the actual link exists or not! Strange.
Thanks Patrick
Wow, thank you for this valuable tipp. I would have never had the idea that a missing background declaration causes such an error.
Thanks for this … all I needed to add was the display:block; rule and it worked like a charm, thanks again.
You’re welcome JC and Malte.
Dear Omer, I am studying Web Design and have been developing a web site using a drop-down rollover menu – had this bug in ie7 when testing and couldn’t find a solution until I found your post – so simple – thanks so much – you’re a gem. Jay
@jay, thanks for the good words.
I’m glad to hear it works for you
THANK YOU SO MUCH!!!!! Such a simple fix, and it worked like a charm. You have returned calm to my existence
Namaste, -Tim
Thank you, it works very good.
It works also if you have a div-element with display:none and :hover display:block
Thanks a lot! I was just fighting with this problem and you’ve saved my time
This Article is the best!!!
Thx