2016-03-27 170 views
0

*級聯下拉菜單

我不知道我在做什麼錯在這裏,所以你能幫助我嗎?我想創建一個級聯下拉菜單,我看不出我做錯了什麼。我已經嘗試了一切。我只是出出主意

*

這裏是我的代碼

<style type="text/css"> 
 
body { 
 
    background:#bf5c71 url('australia1.jpg'); 
 
} 
 
    
 
.clearfix:after { 
 
    display:block; 
 
    clear:both; 
 
} 
 
    
 
/*----- Menu Outline -----*/ 
 
.menu-wrap { 
 
    width:100%; 
 
    box-shadow:0px 1px 3px rgba(0,0,0,0.2); 
 
    background:#3e3436; 
 
} 
 
    
 
.menu { 
 
    width:1000px; 
 
    margin:0px auto; 
 
} 
 
    
 
.menu li { 
 
    margin:0px; 
 
    list-style:none; 
 
    font-family:'Ek Mukta'; 
 
} 
 
    
 
.menu a { 
 
    transition:all linear 0.15s; 
 
    color:#919191; 
 
} 
 
    
 
.menu li:hover > a, .menu .current-item > a { 
 
    text-decoration:none; 
 
    color:#be5b70; 
 
} 
 
    
 
.menu .arrow { 
 
    font-size:11px; 
 
    line-height:0%; 
 
} 
 
    
 
/*----- Top Level -----*/ 
 
.menu > ul > li { 
 
    float:left; 
 
    display:inline-block; 
 
    position:relative; 
 
    font-size:19px; 
 
} 
 
    
 
.menu > ul > li > a { 
 
    padding:10px 40px; 
 
    display:inline-block; 
 
    text-shadow:0px 1px 0px rgba(0,0,0,0.4); 
 
} 
 
    
 
.menu > ul > li:hover > a, .menu > ul > .current-item > a { 
 
    background:#2e2728; 
 
} 
 

 
    
 
/*----- Bottom Level -----*/ 
 
.menu li:hover .sub-menu, 
 
.menu li:hover .sub-menu1{ 
 
    z-index:1; 
 
    opacity:1; 
 
} 
 
    
 
.sub-menu { 
 
    width:160%; 
 
    padding:5px 0px; 
 
    position:absolute; 
 
    top:100%; 
 
    left:0px; 
 
    z-index:-1; 
 
    opacity:0; 
 
    transition:opacity linear 0.15s; 
 
    box-shadow:0px 2px 3px rgba(0,0,0,0.2); 
 
    background:#2e2728; 
 
} 
 

 
.sub-menu1 { 
 
    width:100%; 
 
    padding:0px 0px; 
 
    position:relative; 
 
\t top:100%; 
 
    left:370px; 
 
    z-index:100; 
 
    opacity:50; 
 
    transition:opacity linear 0.15s; 
 
    box-shadow:0px 2px 3px rgba(0,0,0,0.2); 
 
    background:#2e2758; 
 
\t 
 
} 
 

 
.sub-menu li, 
 
.sub-menu1 li 
 
{ 
 
    display:block; 
 
    font-size:16px; 
 
} 
 

 
.sub-menu li a{ 
 
    padding:10px 30px; 
 
    display:block; 
 
} 
 

 
.sub-menu1 li a{ 
 
\t padding:10px 10px; 
 
    display:block; 
 
} 
 
    
 
.sub-menu li a:hover, .sub-menu .current-item a, 
 
.sub-menu1 li a:hover, .sub-menu1 .current-item a 
 
{ 
 
    background:#3e3436; 
 
} 
 

 
</style> 
 
</body> 
 
\t </html>
<html> 
 

 
<head> 
 
     
 
<title> Australia </title> 
 
</head> 
 
<body> 
 
<div class="menu-wrap"> 
 
    <nav class="menu"> 
 
     <ul class="clearfix"> 
 
      <li><a href="#">Acasa</a></li> 
 
      <li><a href="#">Obiective turistice<span class="arrow">&#9660;</span></a> 
 
       <ul class="sub-menu"> 
 
        <li><a href="#">Sydney</a> 
 
\t \t \t \t \t \t <ul class="sub-menu1"> 
 
\t \t \t \t \t \t \t <li><a href="#">Test</a> 
 
\t \t \t \t \t \t </ul> \t 
 
\t \t \t \t \t </li> 
 
        <li><a href="#">Melbourne</a></li> 
 
        <li><a href="#">Brisbane</a></li> 
 
        <li><a href="#">Perth</a></li> 
 
       </ul> 
 
      </li> 
 
\t \t \t <li class="current-item"><a href="#">Galerie Foto</a></li> 
 
      <li><a href="#">Video</a></li> 
 
     </ul> 
 
    </nav> 
 
</div>

+0

總是發佈的jsfiddle爲更好的解釋 – geeksal

+0

我覺得我做@geeksal –

+0

請更多地討論 - 什麼你的意思級聯菜單。我的意思是他們是不同類型的這種菜單,你真正想要的是哪一種? – geeksal

回答

0

或者你可以有你的子菜單的缺口?這真的取決於你想要什麼。你能舉一些例子嗎?下面是我在談論的縮進我的意思:

所有的

body { 
 
    background:#bf5c71 url('australia1.jpg'); 
 
} 
 
    
 
.clearfix:after { 
 
    display:block; 
 
    clear:both; 
 
} 
 
    
 
/*----- Menu Outline -----*/ 
 
.menu-wrap { 
 
    width:100%; 
 
    box-shadow:0px 1px 3px rgba(0,0,0,0.2); 
 
    background:#3e3436; 
 
} 
 
    
 
.menu { 
 
    width:1000px; 
 
    margin:0px auto; 
 
} 
 
    
 
.menu li { 
 
    margin:0px; 
 
    list-style:none; 
 
    font-family:'Ek Mukta'; 
 
} 
 
    
 
.menu a { 
 
    transition:all linear 0.15s; 
 
    color:#919191; 
 
} 
 
    
 
.menu li:hover > a, .menu .current-item > a { 
 
    text-decoration:none; 
 
    color:#be5b70; 
 
} 
 
    
 
.menu .arrow { 
 
    font-size:11px; 
 
    line-height:0%; 
 
} 
 
    
 
/*----- Top Level -----*/ 
 
.menu > ul > li { 
 
    float:left; 
 
    display:inline-block; 
 
    position:relative; 
 
    font-size:19px; 
 
} 
 
    
 
.menu > ul > li > a { 
 
    padding:10px 40px; 
 
    display:inline-block; 
 
    text-shadow:0px 1px 0px rgba(0,0,0,0.4); 
 
} 
 
    
 
.menu > ul > li:hover > a, .menu > ul > .current-item > a { 
 
    background:#2e2728; 
 
} 
 

 
    
 
/*----- Bottom Level -----*/ 
 
.menu li:hover .sub-menu, 
 
.menu li:hover .sub-menu1{ 
 
    z-index:1; 
 
    opacity:1; 
 
} 
 
    
 
.sub-menu { 
 
    width:160%; 
 
    padding:5px 0px; 
 
    position:absolute; 
 
    top:100%; 
 
    left:0px; 
 
    z-index:-1; 
 
    opacity:0; 
 
    transition:opacity linear 0.15s; 
 
    box-shadow:0px 2px 3px rgba(0,0,0,0.2); 
 
    background:#2e2728; 
 
} 
 

 
.sub-menu1 { 
 
    width:100%; 
 
    padding:0px 0px; 
 
    position:relative; 
 
\t top:100%; 
 
    left:370px; 
 
    z-index:100; 
 
    opacity:50; 
 
    transition:opacity linear 0.15s; 
 
    box-shadow:0px 2px 3px rgba(0,0,0,0.2); 
 
    background:#2e2758; 
 
\t 
 
} 
 

 
.sub-menu li, 
 
.sub-menu1 li 
 
{ 
 
    display:block; 
 
    font-size:16px; 
 
} 
 

 
.sub-menu li a{ 
 
    padding:10px 30px; 
 
    display:block; 
 
} 
 

 
.sub-menu1 li a{ 
 
\t padding:10px 10px; 
 
    display:block; 
 
} 
 
    
 
.sub-menu li a:hover, .sub-menu .current-item a, 
 
.sub-menu1 li a:hover, .sub-menu1 .current-item a 
 
{ 
 
    background:#3e3436; 
 
}
<div class="menu-wrap"> 
 
    <nav class="menu"> 
 
     <ul class="clearfix"> 
 
      <li><a href="#">Acasa</a></li> 
 
      <li><a href="#">Obiective turistice<span class="arrow">&#9660;</span></a> 
 
       <ul class="sub-menu"> 
 
        <li> 
 
         <a href="#">Sydney</a> 
 
\t \t    <ul> 
 
         <li><a href="#">Test</a> 
 
         </ul> 
 
\t \t \t \t  </li> 
 
        <li><a href="#">Melbourne</a></li> 
 
        <li><a href="#">Brisbane</a></li> 
 
        <li><a href="#">Perth</a></li> 
 
       </ul> 
 
      </li> 
 
\t \t \t <li class="current-item"><a href="#">Galerie Foto</a></li> 
 
      <li><a href="#">Video</a></li> 
 
     </ul> 
 
    </nav> 
 
</div>

1

您可以使用相鄰兄弟選擇更多信息請訪問此鏈接On a CSS hover event, can I change another div's styling?

display:none初始設置爲sub-menu1類和懸停的sub-menu li adisplay相鄰sub-menu1回到block

下面是代碼:

body { 
 
    background:#bf5c71 url('australia1.jpg'); 
 
} 
 

 
.clearfix:after { 
 
    display:block; 
 
    clear:both; 
 
} 
 

 
/*----- Menu Outline -----*/ 
 
.menu-wrap { 
 
    width:100%; 
 
    box-shadow:0px 1px 3px rgba(0,0,0,0.2); 
 
    background:#3e3436; 
 
} 
 

 
.menu { 
 
    width:1000px; 
 
    margin:0px auto; 
 
} 
 

 
.menu li { 
 
    margin:0px; 
 
    list-style:none; 
 
    font-family:'Ek Mukta'; 
 
} 
 

 
.menu a { 
 
    transition:all linear 0.15s; 
 
    color:#919191; 
 
} 
 

 
.menu li:hover > a, .menu .current-item > a { 
 
    text-decoration:none; 
 
    color:#be5b70; 
 
} 
 

 
.menu .arrow { 
 
    font-size:11px; 
 
    line-height:0%; 
 
} 
 

 
/*----- Top Level -----*/ 
 
.menu > ul > li { 
 
    float:left; 
 
    display:inline-block; 
 
    position:relative; 
 
    font-size:19px; 
 
} 
 

 
.menu > ul > li > a { 
 
    padding:10px 40px; 
 
    display:inline-block; 
 
    text-shadow:0px 1px 0px rgba(0,0,0,0.4); 
 
} 
 

 
.menu > ul > li:hover > a, .menu > ul > .current-item > a { 
 
    background:#2e2728; 
 
} 
 

 

 
/*----- Bottom Level -----*/ 
 
.menu li:hover .sub-menu, 
 
.menu li:hover .sub-menu1{ 
 
    z-index:1; 
 
    opacity:1; 
 
} 
 

 
.sub-menu { 
 
    width:160%; 
 
    padding:5px 0px; 
 
    position:absolute; 
 
    top:100%; 
 
    left:0px; 
 
    z-index:-1; 
 
    opacity:0; 
 
    transition:opacity linear 0.15s; 
 
    box-shadow:0px 2px 3px rgba(0,0,0,0.2); 
 
    background:#2e2728; 
 
} 
 

 
.sub-menu1 { 
 
    width:100%; 
 
    padding:0px 0px; 
 
    position:relative; 
 
    top:100%; 
 
    left:370px; 
 
    z-index:100; 
 
    opacity:50; 
 
    transition:opacity linear 0.15s; 
 
    box-shadow:0px 2px 3px rgba(0,0,0,0.2); 
 
    background:#2e2758; 
 
    display: none; 
 

 
} 
 

 

 
.sub-menu li, 
 
.sub-menu1 li 
 
{ 
 
    display:block; 
 
    font-size:16px; 
 
} 
 

 

 

 
.sub-menu li a:hover, .sub-menu .current-item a, 
 
.sub-menu1 li a:hover, .sub-menu1 .current-item a 
 
{ 
 
    background:#3e3436; 
 
    display: block; 
 
} 
 

 

 
.sub-menu li a:hover + .sub-menu1{ 
 
    display:block; 
 
    padding:10px 10px; 
 
}
<div class="menu-wrap"> 
 
    <nav class="menu"> 
 
     <ul class="clearfix"> 
 
      <li><a href="#">Acasa</a></li> 
 
      <li><a href="#">Obiective turistice<span class="arrow">&#9660;</span></a> 
 
       <ul class="sub-menu"> 
 
        <li><a href="#">Sydney</a> 
 
         <ul class="sub-menu1"> 
 
          <li><a href="#">Test</a> 
 
         </ul> 
 
        </li> 
 
        <li><a href="#">Melbourne</a></li> 
 
        <li><a href="#">Brisbane</a></li> 
 
        <li><a href="#">Perth</a></li> 
 
       </ul> 
 
      </li> 
 
      <li class="current-item"><a href="#">Galerie Foto</a></li> 
 
      <li><a href="#">Video</a></li> 
 
     </ul> 
 
    </nav> 
 
</div>

0

首先,你必須寫0,而不是0像素。 您必須使子菜單1顯示:無;那麼當鼠標在悉尼上時,子菜單必須顯示:block; 我有固定出頭,這將是你的代碼:

body { 
 
    background: #bf5c71; 
 
} 
 

 
.clearfix:after { 
 
    display: block; 
 
    clear: both; 
 
} 
 

 
/*----- Menu Outline -----*/ 
 
.menu-wrap { 
 
    width: 100%; 
 
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); 
 
    background: #3e3436; 
 
} 
 

 
.menu { 
 
    width: 1000px; 
 
    margin: 0 auto; 
 
} 
 

 
.menu li { 
 
    margin: 0; 
 
    list-style: none; 
 
    font-family: 'Ek Mukta'; 
 
} 
 

 
.menu a { 
 
    transition: all linear 0.15s; 
 
    color: #919191; 
 
} 
 

 
.menu li:hover > a, .menu .current-item > a { 
 
    text-decoration: none; 
 
    color: #be5b70; 
 
} 
 

 
.menu .arrow { 
 
    font-size: 11px; 
 
    line-height: 0; 
 
} 
 

 
/*----- Top Level -----*/ 
 
.menu > ul > li { 
 
    float: left; 
 
    display: inline-block; 
 
    position: relative; 
 
    font-size: 19px; 
 
} 
 

 
.menu > ul > li > a { 
 
    padding: 10px 40px; 
 
    display: inline-block; 
 
    text-shadow: 0 1px 0 rgba(0, 0, 0, 0.4); 
 
} 
 

 
.menu > ul > li:hover > a, .menu > ul > .current-item > a { 
 
    background: #2e2728; 
 
} 
 

 
/*----- Bottom Level -----*/ 
 
.menu li:hover .sub-menu, 
 
.menu li:hover .sub-menu1 { 
 
    z-index: 1; 
 
    opacity: 1; 
 
} 
 

 
.sub-menu { 
 
    width: 160%; 
 
    padding: 5px 0; 
 
    position: absolute; 
 
    top: 0; 
 
    left: 0; 
 
    z-index: -1; 
 
    opacity: 0; 
 
    transition: opacity linear 0.15s; 
 
    box-shadow: 0 2px 3px rgba(0, 0, 0, 0.2); 
 
    background: #2e2728; 
 
} 
 

 
#sydney:hover .sub-menu1 { 
 

 
    display: block; 
 

 
} 
 

 
.sub-menu1 { 
 
    width: 100%; 
 
    padding: 0; 
 
    position: relative; 
 
    top: 0; 
 
    left: 370px; 
 
    z-index: 100; 
 
    opacity: 50; 
 
    transition: opacity linear .15s; 
 
    box-shadow: 0 2px 3px rgba(0, 0, 0, 0.2); 
 
    background: #2e2758; 
 
    display: none; 
 

 
} 
 

 
.sub-menu li, 
 
.sub-menu1 li { 
 
    font-size: 16px; 
 
} 
 

 
.sub-menu li a { 
 
    padding: 10px 30px; 
 
    display: block; 
 
} 
 

 
.sub-menu li a:hover, .sub-menu .current-item a, 
 
.sub-menu1 li a:hover, .sub-menu1 .current-item a { 
 
    background: #3e3436; 
 
}
<div class="menu-wrap"> 
 
    <nav class="menu"> 
 
     <ul class="clearfix"> 
 
      <li><a href="#">Acasa</a></li> 
 
      <li><a href="#">Obiective turistice<span class="arrow">&#9660;</span></a> 
 
       <ul class="sub-menu"> 
 
        <li id="sydney"><a href="#">Sydney</a> 
 
         <ul class="sub-menu1"> 
 
          <li><a href="#">Test</a></li> 
 
         </ul> 
 
        </li> 
 
        <li><a href="#">Melbourne</a></li> 
 
        <li><a href="#">Brisbane</a></li> 
 
        <li><a href="#">Perth</a></li> 
 
       </ul> 
 
      </li> 
 
      <li class="current-item"><a href="#">Galerie Foto</a></li> 
 
      <li><a href="#">Video</a></li> 
 
     </ul> 
 
    </nav> 
 
</div>