Dor Cohen
Dor Cohen

Reputation: 17080

Why the following dropup menu hover doesn't work on IE

I saw the following drop-up menu example:

http://jsfiddle.net/W5FWW/360/

html:

<div id="menu">
    <ul>
        <li><center><a href="#">Home</a></center>
                <ul>
                        <li><a href="#">About Us</a></li>
                        <li><a href="#">Disclaimer</a></li>
                </ul>
        </li>
    </ul>
</div>​

This example works for me perfectly on Chrome but fails to work on IE 9,
The menu should open when I'm hovering the Menu link.
(It works when I open it on jsfiddle but when copying it to html file and runs this independently it fails)

Why this working on Chrome and doesn't works on IE 9? What can I do?

Thanks!

Upvotes: 0

Views: 2593

Answers (4)

John Smith
John Smith

Reputation: 1780

You don't have a doctype set do you.

"Note: In IE there must be declared a <!DOCTYPE> for the :hover selector to work on other elements than the <a> element." http://www.w3schools.com/cssref/sel_hover.asp

You have a :hover on the <li>:

#menu:hover ul li:hover ul li:hover ul { 
    position: absolute;
    margin-left: 145px;
    margin-top: -22px;
    font: 10px;
}

Upvotes: 2

AspiringCanadian
AspiringCanadian

Reputation: 1665

Here is the complete code that is working on IE7/8/9 and other browsers. Please read up on Doctype declaration.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style>
div, ul, li{ padding:0; margin:0; list-style:none;}
#menu { 
    margin-top: 100px;
    float: left;
    line-height: 10px; 
    left: 200px;}
#menu a { 
    display: block; 
    text-decoration: none; 
    color: #3B5330;}
#menu a:hover { background: #B0BD97;}
#menu ul li ul li a:hover { 
    background: #ECF1E7; 
    padding-left:9px;
    border-left: solid 1px #000;}
#menu ul li ul li {
    width: 140px; 
    border: none; 
    color: #B0BD97;  
    padding-top: 3px; 
    padding-bottom:3px; 
    padding-left: 3px; 
    padding-right: 3px; 
    background: #B0BD97;
    z-index:1;
}
#menu ul li ul li a { 
    font: 11px arial; 
    font-weight:normal; 
    font-variant: small-caps; 
    padding-top:3px; 
    padding-bottom:3px;}
#menu ul li {
    float: left; 
    width: 146px; 
    font-weight: bold; 
    border-top: solid 1px #283923; 
    border-bottom: solid 1px #283923; 
    background: #979E71;}
#menu ul li a { 
    font-weight: bold;
    padding: 15px 10px;}
#menu li{ 
    position:relative; 
    float:left;}
#menu ul li ul, #menu:hover ul li ul, #menu:hover ul li:hover ul li ul{ 
    display:none;
    list-style-type:none; 
    width: 140px;}
#menu:hover ul, #menu:hover ul li:hover ul, #menu:hover ul li:hover ul li:hover ul { 
    display:block;}
#menu:hover ul li:hover ul li:hover ul { 
    position: absolute;
    margin-left: 145px;
    margin-top: -22px;
    font: 10px;}
#menu:hover ul li:hover ul { 
    position: absolute;
    margin-top: 1px;
    font: 10px;
}
#menu>ul>li:hover>ul { 
    bottom:100%;
    border-bottom: 1px solid transparent
}​
</style>
</head>

<body>
<div id="menu">
    <ul>
        <li><center><a href="#">Home</a></center>
                <ul>
                        <li><a href="#">About Us</a></li>
                        <li><a href="#">Disclaimer</a></li>
                </ul>
        </li>
    </ul>
</div>​
</body>
</html>

Upvotes: 1

Stuart Burrows
Stuart Burrows

Reputation: 10814

The only way I can get this to fail is by throwing IE into Quirks mode. Ensure you have a valid doctype in your file and you should be fine. Please advise if this is not the issue :)

Upvotes: 1

I've tested this on:

  • Firefox 17.0.1
  • Chrome 21.0.1180.89 m
  • IE 9.0.8112.16421

and it works great.

Just as a word of advice do not use CSS drop-downs for key navigation in case old browsers are unable to support it. You risk loosing key functionality.

Also depending on your DOCTYPE! <center> is obsolete and you should consider centering using CSS instead.

<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <link rel="stylesheet" href="style.css" />
        <meta charset="UTF-8">
    </head>
    <body>
        <div id="menu">
            <ul>
                <li class="centretext"><a href="#">Home</a>
                        <ul>
                                <li><a href="#">About Us</a></li>
                                <li><a href="#">Disclaimer</a></li>
                        </ul>
                </li>
            </ul>
        </div>​
    </body>
</html>

Upvotes: 1

Related Questions