2009-08-21 11 views
0

Das folgende Dropdown-Menü funktioniert gut in modernen Browsern (IE7/Firefox), aber nicht in IE6. Kann jemand eine Lösung vorschlagen?Dropdown-Menü funktioniert nicht in IE6

CSS:

#menu { 
    height: 29px; 
    background: url(img/menu.png) repeat-x top; 
    border-left: 1px solid #0b2f3e; 
    border-right: 1px solid #0b2f3e; 
    position: relative; 
} 

#menu ul { 
    display: none; 
    position: absolute; 
    top: 29px; 
    left: 0; 
    background: #316f86; 
    width: 220px; 
    z-index: 10; 
} 

#menu ul ul { 
    top: -1px; 
    left: 220px; 
    width: 200px; 
    border: 1px solid #4a7a8c; 
    border-bottom: none; 
} 

#menu li { 
    float: left; 
    display: block; 
    position: relative; 
} 

#menu li li { 
    float: none; 
} 

#menu li a { 
    float: left; 
    display: block; 
    color: #fff; 
    height: 16px; 
    line-height: 16px; 
    padding: 7px 20px 6px 20px; 
    border-right: 1px solid #0b2f3e; 
} 

#menu ul li a { 
    float: none; 
    border-right: none; 
    border-bottom: 1px solid #4a7a8c; 
} 

#menu li a:hover { 
    border-bottom: none; 
} 

#menu ul li a:hover { 
    color: #c0e8ff; 
    border-bottom: 1px solid #4a7a8c; 
} 

.menu-bottom { 
    background: url(img/menu.png) repeat-x bottom; 
} 

.menu-top { 
    background: url(img/menu.png) repeat-x top; 
} 

#menu li:hover ul ul, #menu li:hover ul ul ul, #menu li:hover ul ul ul ul{ 
display:none; 
} 
#menu li:hover ul, #menu li li:hover ul, #menu li li li:hover ul, #menu li li li li:hover ul{ 
display:block; 
} 

#menu img { 
    vertical-align: middle; 
    overflow: hidden; 
    width: 16px; 
    height: 16px; 
    margin: 0 8px 0 0; 
} 

jQuery: (sollte kein Problem mit Jquery sein)

// dropdown menu (unlimited sub-levels) 
jQuery("#menu ul").css({display: "none"}); // Opera Fix 

jQuery("#menu li").hover(
    function(){ 
     if (jQuery(this).parent().attr("id") == 'menu') { 
      jQuery(this).removeClass('menu-top'); 
      jQuery(this).addClass('menu-bottom'); 
     } 
     jQuery(this).find('ul:first').css({visibility: "visible",display: "none"}).fadeIn(500); 

    }, 
    function(){ 
     if (jQuery(this).parent().attr("id") == 'menu') { 
      jQuery(this).removeClass('menu-bottom'); 
      jQuery(this).addClass('menu-top'); 
     } 
     jQuery(this).find('ul:first').css({visibility: "hidden"}); 
    } 
); 

Ich bin sicher, es ist etwas mit, wie IE6 behandelt Schwimmer/blocks..but kann einfach nicht bekommen den Dreh raus haben.

+0

können Sie es spotten jsbin.com oder pastebin.me – redsquare

Antwort

3

Warum erfinden Sie das Rad neu. Gutes Menüsystem ist superfish oder Suckerfish. Bewährt auf IE6 usw.

+0

ich das Rad neu erfinden, weil ich meine eigene Version entwickeln wollen. Es ist einfacher als das Anpassen der vorgefertigten Menüs. und ich brauche es auch in jQuery. Das Problem ist, dass, wenn ich float entfernen: links von #menu li {} es erscheint .. so ist das Problem nicht in jquery .. es ist einfach float: links..aber es sieht hässlich aus, wenn es entfernt –

+0

Tweaking Super/Suckerfish Menüs ist trivial, wenn Sie CSS verstehen. –

+0

eigentlich sollte man float halten: links; und fügte hinzu: inline – albert

1

Es lohnt sich einen Blick auf Stu Nicholls CSS Play Website, seine menu s Seite hält Dutzende von Beispielen, von denen viele Cross-Browser-kompatibel und inklusive IE6 nehmen.

0

versuchen, die jquery Live-Methode anstelle von Hover

jQuery("#menu li").hover -> jQuery("#menu li").live("hover", function() 

es könnte das Problem mit Hover beheben nicht gefeuert in IE6

0

Dank all .. ich es geschafft, zu beheben das CSS und es mit IE6 arbeiten lassen :)

Hier ist es nur für den Fall, dass jemand es braucht.

#menu, #menu ul { 
    position: relative; 
    z-index: 300; 
    width: 100%; 
} 

#menu { 
    height: 29px; 
    background: url(img/menu.png) repeat-x top; 
    border-left: 1px solid #0b2f3e; 
    border-right: 1px solid #0b2f3e; 
} 

#menu ul { 
    width: 230px; 
    position: absolute; 
    display: none; 
    top: 29px; 
    left: 0; 
    background: #316f86; 
} 

#menu ul ul { 
    width: 232px; 
    top: -1px; 
    left: 230px; 
    background: #316f86; 
    border: 1px solid #4a7a8c;border-bottom: none; 
} 

#menu li { 
    float: left; 
    position: relative; 
} 

#menu a { 
    display: block; 
    padding: 9px 20px 8px 20px; 
    color: #fff; 
    border-right: 1px solid #0b2f3e; 
} 

#menu li ul a { 
    float: left; 
    height: auto; 
    border-right: none; 
    border-bottom: 1px solid #4a7a8c; 
    width: 190px; 
} 

#menu li a:hover { 
    border-bottom: none; 
} 

#menu li ul a:hover { 
    color: #c0e8ff; 
    border-bottom: 1px solid #4a7a8c; 
} 

.menu-bottom { 
    background: url(img/menu.png) repeat-x bottom; 
} 

.menu-top { 
    background: url(img/menu.png) repeat-x top; 
} 

#menu li:hover ul ul, #menu li:hover ul ul ul, #menu li:hover ul ul ul ul {display:none;} 
#menu li:hover ul, #menu li li:hover ul, #menu li li li:hover ul, #menu li li li li:hover ul {display:block;} 

#menu img { 
    vertical-align: middle; 
    overflow: hidden; 
    width: 16px; 
    height: 16px; 
    margin: 0 8px 0 0; 
} 
+0

@ redsquare's Lösung war richtig, die Hände nach unten. während du denkst, dass du "das css reparierst, damit es in IE6 funktioniert", tat jQuery tatsächlich die ganze Zeit; was auch immer du "repariert" hast, sah einfach gut aus, nachdem du einige Änderungen vorgenommen hast. : Hover funktioniert nicht mit einem anderen Element als in IE6. Aus diesem Grund verbrachte HTMLDOG x-viele Stunden mit der Entwicklung von Suckerfish-Dropdowns, um browserübergreifend kompatibel zu sein, speziell für IE6. und warum @redsquare sagte, dass du das Rad nicht neu erfinden musst. – albert