2014-01-17 52 views
0

所以我做了一個菜單,用css3過渡的下拉效果,但我的問題是,你可以在背景顯示之前看到文本,當然這個想法是看不到的背景前的文字。下拉菜單文本顯示在背景之前

我做了第j sfiddle

HTML:

<nav> 
    <ul> 
     <li>Home</li> 
     <li>Parrent Link 
      <ul> 
       <li>Child Link</li> 
       <li>Child Link</li> 
       <li>Parrent Link 
        <ul> 
         <li>Child Link</li> 
         <li>Child Link</li> 
         <li>Child Link</li> 
         <li>Child Link</li> 
         <li>Child Link</li> 
        </ul> 
       </li> 
      </ul> 
     </li> 
     <li>About</li> 
     <li>Contact</li> 
    </ul> 
</nav> 

CSS:

nav { 
     position: fixed; 
     top: 0; 
     width: 100%; 
     height: 50px; 
     background: #30a0ff; 
     z-index: 2; 
     box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.3); 
} 

nav > ul { 
     position: relative; 
    margin: 0 auto; 
    padding: 0; 
    width: 100%; 
    list-style: none; 
    text-align: center; 
} 

nav > ul > li { 
    position: relative; 
    display: inline; 
    padding: 12px 20px; 
    line-height: 50px; 
    font-size: 22px; 
    color: #fff; 
    cursor: pointer; 
} 

nav > ul > li:last-child { 
    margin: 0 -20px 0 0; 
} 

nav ul li { 
    -webkit-transition: all 0.2s ease-in-out; 
    -moz-transition: all 0.2s ease-in-out; 
    -ms-transition: all 0.2s ease-in-out; 
    -o-transition: all 0.2s ease-in-out; 
    transition: all 0.2s ease-in-out; 
} 

nav ul li:hover { 
    background-color: #0f71c4; 
} 

nav > ul > li > ul { 
    position: absolute; 
    top: 50px; 
    left: 0; 
    height: 0; 
    padding: 0; 
    list-style: none; 
    line-height: 20px; 
    font-size: 17px; 
    background-color: #30a0ff; 
    overflow: hidden; 
} 

nav > ul > li:hover > ul { 
    min-height: 110px; 
    overflow: visible; 
} 

nav > ul > li > ul > li:first-child { 
    padding: 15px 20px 5px 20px; 
} 

nav > ul > li > ul > li:last-child { 
    padding: 5px 20px 15px 20px; 
} 

nav > ul > li > ul > li { 
    position: relative; 
    padding: 5px 20px; 
    min-width: 150px; 
    text-align: left; 
} 

nav ul li ul { 
    box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.3); 
    -webkit-transition: all 0.3s ease-in-out; 
    -moz-transition: all 0.3s ease-in-out; 
    -ms-transition: all 0.3s ease-in-out; 
    -o-transition: all 0.3s ease-in-out; 
    transition: all 0.3s ease-in-out; 
} 

nav > ul > li > ul > li > ul { 
    position: absolute; 
    left: 190px; 
    top: 0; 
    padding: 0; 
    width: 0; 
    list-style: none; 
    font-size: 16px; 
    background-color: #30a0ff; 
    overflow: hidden; 
} 

nav > ul > li > ul > li:hover > ul { 
    min-width: 150px; 
} 

nav > ul > li > ul > li > ul > li { 
    position: relative; 
    padding: 5px 20px; 
    min-width: 150px; 
} 

nav > ul > li > ul > li > ul > li:first-child { 
    padding: 15px 20px 5px 20px; 
} 

nav > ul > li > ul > li > ul > li:last-child { 
    padding: 5px 20px 15px 20px; 
} 

回答

2

我剛添加的不透明度到現有的CSS:

爵士小提琴:

http://jsfiddle.net/r9Dyq/2/

CSS:

nav > ul > li > ul { 
    position: absolute; 
    top: 50px; 
    left: 0; 
    height: 0; 
    padding: 0; 
    list-style: none; 
    line-height: 20px; 
    font-size: 17px; 
    background-color: #30a0ff; 
    overflow: hidden; 
    opacity:0; /*newly added */ 
} 

nav > ul > li:hover > ul { 
    min-height: 110px; 
    overflow: visible; 
    opacity:1; /*newly added */ 
} 
+0

謝謝,不知道爲什麼我沒有想到那:) – Legarndary

0

只要不改變overflow屬性:

nav > ul > li:hover > ul { 
    min-height: 110px; 
    /*overflow: visible; Remove this*/ 
} 

車CK這個http://jsfiddle.net/r9Dyq/1/

+1

此次榮獲」工作,它無線會隱藏第二個子菜單。 – Adrift

+1

Yup @Adrift我的錯誤我沒有看到第一個嘗試的第二個子菜單 – DaniP