我想用SubMenus的垂直SubMenu和Horizo​​ntal SubMenus制作纯css水平导航

时间:2013-07-30 13:53:09

标签: html css3 css-transitions navigationbar

我想修复这个小提琴,你可以看到它不能正常工作。 我想横向和子菜单垂直和水下子菜单水平使这个导航,但问题是我也使用过渡,但它不正确。 第一个子菜单没有顺利下降,但顺利推出,第三个菜单不像平滑滚动和推出那样工作。 我想解决这个问题,我想要帮助如何解决这个问题。 这是小提琴, 所有代码都包括在内。  http://jsfiddle.net/hsn0/nQneb/

CSS

#nav {
height: auto;
width: auto;
}
#nav ul {
margin: 0px;
padding: 0px;
list-style-type: none;
}
#nav ul li {
float: left;
position: relative;
}
#nav ul li a {
line-height: 30px;
text-decoration: none;
text-align: center;
display: block;
width: 100px;
height: 30px;
border: thin solid #999;
color: #FFF;
background-color: #0CF;
-webkit-transition: all 1s;
-moz-transition: all 1s;
-ms-transition: all 1s;
-o-transition: all 1s;
transition: all 1s;
 }
 #nav ul li a:hover {
background-color: #0C3;
 }
 #nav ul li ul {
position: absolute;
visibility: hidden;
-webkit-transition: all 1s linear 0s;
-moz-transition: all 1s linear 0s;
-ms-transition: all 1s linear 0s;
-o-transition: all 1s linear 0s;
transition: all 1s linear 0s;
overflow: hidden;
height: 0px;
 }
 #nav ul li:hover ul {
height: 100px;
visibility: visible;
overflow: visible;
 }
 #nav ul li ul li {
-ms-transition: all 1s;
-o-transition: all 1s;
 }
 #nav ul li ul li a {
background-color: #666;
-webkit-transition: all 1s;
-moz-transition: all 1s;
-ms-transition: all 1s;
-o-transition: all 1s;
transition: all 1s;
 }
 #nav ul li ul li a:hover {
background-color: #C30;
 }
 #nav ul li ul li ul {
position: absolute;
left: 102px;
top: 0px;
display: none;
-webkit-transition: all 1s ease 0s;
-moz-transition: all 1s ease 0s;
-ms-transition: all 1s ease 0s;
-o-transition: all 1s ease 0s;
transition: all 1s ease 0s;
overflow: hidden;
visibility: hidden;
width: 0px;
 }
 #nav ul li ul li ul li {
float: left;
position: relative;
 }
 #nav ul li ul li:hover ul {
width: 104px;
display: block;
/* [disabled]overflow: visible; */
visibility: visible;
 }

 **html**

<nav id="nav">
 <ul>
   <li><a href="#">Item1</a>
 <ul>
   <li><a href="#">Sub1</a></li>
  <li><a href="#">Sub1</a></li>
   <li><a href="#">Sub1</a>
     <ul>
 <li><a href="#">Sub2</a></li>
        <li><a href="#">Sub2</a></li>
        <li><a href="#">Sub2</a></li>
     </ul>

    </li>
   </ul>
  </li>
 </ul>
</nav>

2 个答案:

答案 0 :(得分:0)

请查看此demo

我觉得主要问题是由于能见度和溢出,我们可以转换不透明度和高度。

我使用了很少的菜单部分...我尝试了高度,虽然它也适用于所有。

#nav ul li ul {
    position: absolute; 
    -webkit-transition: height  1s linear 0s;
    -moz-transition: height  1s linear 0s;
    -ms-transition: height  1s linear 0s;
    -o-transition: height  1s linear 0s;
    transition: height 1s linear 0s;    
    height: 0px;
    overflow:hidden;
}
#nav ul li:hover ul {
    height: 100px;

        -webkit-transition: height 1s linear 0s;
    -moz-transition: height 1s linear 0s;
    -ms-transition: height 1s linear 0s;
    -o-transition: height 1s linear 0s;
    transition: height 1s linear 0s;
}

答案 1 :(得分:0)

我希望,在css之下将解决你的问题

         #nav {
            height: auto;
            width: auto;
        }
        #nav ul {
            margin: 0px;
            padding: 0px;
            list-style-type: none;
        }
        #nav ul li {
            float: left;
            position: relative;
        }
        #nav ul li a {
            line-height: 30px;
            text-decoration: none;
            text-align: center;
            display: block;
            width: 100px;
            height: 30px;
            border: thin solid #999;
            color: #FFF;
            background-color: #0CF;
            -webkit-transition: all 0.3s ease-out;
            -moz-transition: all 0.3s ease-out;
            -o-transition: all 0.3s ease-out;
            /*transition: all 0.3s ease-out;*/
            transition:display 0s linear 0.5s,opacity 0.5s linear;
        }
        #nav ul li a:hover {
            background-color: #0C3;
        }
        #nav ul li ul {
            position: absolute;
            height:0;
            visibility:hidden;
            opacity:0;
            -webkit-transition: all 1s ease-out;
            -moz-transition: all 1s ease-out;
            -o-transition: all 1s ease-out;
            transition: all 1s ease-out;
        }
        #nav ul li:hover ul {
            opacity:1;
            visibility:visible; 
            overflow: visible;
        }

        #nav ul li ul li a {
            background-color: #666;
            -webkit-transition: all 0.3s ease-out;
            -moz-transition: all 0.3s ease-out;
            -o-transition: all 0.3s ease-out;
            transition: all 0.3s ease-out;
        }
        #nav ul li ul li a:hover {
            background-color: #C30;
        }
        #nav ul li ul li ul {
            position: absolute;
            left: 102px;
            top: 0px;
            visibility:hidden !important;
            opacity:0 !important;
            -webkit-transition: all 1s ease-out;
            -moz-transition: all 1s ease-out;
            -o-transition: all 1s ease-out;
            transition: all 1s ease-out;
            overflow: hidden;
        }
        #nav ul li ul li:hover .last {
            opacity:1 !important;
            visibility:visible !important;
            overflow: visible;
        }
        #nav ul li ul li .last li{
            float: left;
            position: relative;
        }
        #navul li ul li .last li a {
            line-height: 30px;
            text-decoration: none;
            text-align: center;
            display: block;
            width: 100px;
            height: 30px;
            border: thin solid #999;
            color: #FFF;
            background-color: #0CF;
            -webkit-transition: all 0.3s ease-out;
            -moz-transition: all 0.3s ease-out;
            -ms-transition: all 0.3s ease-out;
            -o-transition: all 0.3s ease-out;
            transition: all 0.3s ease-out;
        }

HTML

        <nav id="nav">
          <ul>
            <li><a href="#">Item1</a>
            <ul>
              <li><a href="#">Sub1</a></li>
              <li><a href="#">Sub1</a></li>
                <li><a href="#">Sub1</a>
                 <ul class="last">
                    <li><a href="#">Sub2</a></li>
                    <li><a href="#">Sub2</a></li>
                    <li><a href="#">Sub2</a></li>
                 </ul>

                </li>
            </ul>
            </li>
          </ul>

        </nav>