2017-03-22 12 views
0

私は3つのレベルのメニューで作業しています。それは2つのレベルで動作しますが、第3レベルを追加してレベル1にカーソルを合わせると、レベル2とレベル3が表示されます。レベル2のlisを上に置くと、CSSメニューの3番目のレベルが正しく表示されない

私のhtml:

<div id="menuContainer"> 
<div id="menuwrapper"> 
    <ul> 
     <li><a href="#">One 1</a> 
      <ul> 
       <li><a href="#">Two 1</a></li> 
       <li><a href="#">Two 2</a></li> 
      </ul> 
     </li> 
     <li><a href="#">One 2</a> 
      <ul> 
       <li><a href="#">Two 3</a></li> 
       <li><a href="#">Two 4</a></li> 
      </ul> 
     </li> 
     <li><a href="admin.php">One 3</a> 
      <ul>      
       <li> 
        <a href="#">Two 5</font></a> 
        <ul> 
         <li><a href="#"><font size="2">Three 1</font></a></li> 
         <li><a href="#"><font size="2">Three 2</font></a></li>       

        </ul> 
       </li> 
       <li> 
        <a href="#"><font size="2">Two 6</font></a> 
        <ul > 
         <li><a href="#"><font size="2">Three 3</font></a></li> 
         <li><a href="#"><font size="2">Three 4</font></a></li> 
        </ul> 
       </li> 
      </ul> 
     </li> 
    </ul>  
</div> 
</div> 

私のCSS:私はあなたがこれをしたいと思います

/*MENU CSS */ 
#menuwrapper { 
    width:100%; 
    z-index:2000; 
} 
/* for adding arrows to the menu items with sub menus YET TO IMPLEMENT*/ 
#menuwrapper li > a:after { 
    content: ' '; 
} 
#menuwrapper li > a:only-child:after { 
    content: ''; 
} 

/* We remove the margin, padding, and list style of UL and LI components */ 
#menuwrapper ul, #menuwrapper ul li, #menuwrapper ul li ul li{ 
    margin:0; 
    padding:0; 
    list-style:none; 
} 

/* We apply background color and border bottom white and width to 150px */ 
#menuwrapper ul li{ 
    background-color:#2d6aff; 
    border-top:solid 1px black; 
    width:100%; 
    cursor:pointer; 
} 

/* We apply the background hover color when user hover the mouse over of the li component */ 
#menuwrapper ul li:hover{ 
    background-color:#15357F; 
    position:relative; 

} 

/* We apply the link style */ 
#menuwrapper ul li a{ 
    padding:5px 15px; 
    color:#ffffff; 
    display:inline-block; 
    text-decoration:none; 
} 

/**** SECOND LEVEL MENU ****/ 
/* We make the position to absolute for flyout menu and hidden the ul until the user hover the parent li item */ 
#menuwrapper ul li ul{ 
    position:absolute; 
    display:none; 

} 

/* When user has hovered the li item, we show the ul list by applying display:block, note: 150px is the individual menu width. */ 
#menuwrapper ul li:hover ul{ 
    left:100%; 
    min-width:283px; 
    top:0px; 
    display:block; 
} 

/* we apply different background color to 2nd level menu items*/ 
#menuwrapper ul li ul li{ 
    background-color:#EEEEEE; 
    border-left: 1px solid #999999; 
    width:100%; 
} 

/* We change the background color for the level 2 submenu when hovering the menu */ 
#menuwrapper ul li:hover ul li:hover{ 
    background-color:#4cff00; 
} 

/* We style the color of level 2 links */ 
#menuwrapper ul li ul li a{ 
    color:#000000; 
    display:inline-block; 
    width:100%; 
    width: auto; 
} 
/**** THIRD LEVEL MENU ****/ 
/* We make the position to absolute for flyout menu and hidden the ul until the user hover the parent li item */ 
#menuwrapper ul li ul li ul{ 
    position:absolute; 
    display:none; 

} 

/* When user has hovered the li item, we show the ul list by applying display:block, note: 150px is the individual menu width. */ 
#menuwrapper ul li:hover ul li:hover > ul { 

    min-width:283px; 
    top:0px; 
    display:block; 
} 

/* we apply different background color to 3rd level menu items*/ 
#menuwrapper ul li ul li ul { 
    background-color:#EEEEEE; 
    border-left: 1px solid #999999; 
    width:100%; 
} 


/* We style the color of level 3 links */ 
#menuwrapper ul li ul li ul li a{ 
    color:#000000; 
    display:inline-block; 
    width:100%; 
    width: auto; 
} 
+0

#menuwrapper ul li:hover ulを#menuwrapper ul li:hover> ulに変更してください。そのため、直接の子にのみ影響します。 –

答えて

2

See this fiddle

私は親セレクタで遊んで終わりではCSSの2行を追加しました:

#menuwrapper > ul > li:hover > ul { display: block; left: 0; } 
#menuwrapper > ul > li:hover > ul ul { display: none; } 
+0

パーフェクト!どうもありがとうございます! – user7599271

+0

あなたは大歓迎です:) –

関連する問題