如何让这个下拉菜单实际“下拉”

时间:2014-03-06 21:28:25

标签: html css drop-down-menu

我制作的这个导航栏在某些按钮上有下拉菜单。我想这样做,当激活下拉菜单的按钮悬停在上面时,下拉菜单就像这样:http://designmodo.com/demo/css3dropdownmenu/

以下是我的代码的链接:http://jsfiddle.net/w5Ce7/2/

以下是刚粘贴在此处的代码:

HTML

<div id="container">
<div id="navbar">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Questions</a></li>
<li><a href="#">Classes</a></li>
<li><a href="#">Designer</a></li>
<li><a href="#">Flavors</a></li>
<li><a href="#">Cakes</a>
<ul>
<li ><a href="#">Budget Cakes</a></li>
<li><a href="#">Wedding</a>
    <ul>
    <li><a href="#">Wedding 1</a></li>
    <li><a href="#">Wedding 2</a></li>
    <li><a href="#">Wedding 3</a></li>
    <li><a href="#">Wedding 4</a></li>
    <li><a href="#">Wedding 5</a></li>
    <li><a href="#">Wedding 6</a></li>
    </ul>
</li>
<li ><a href="#">Cakes to Go</a></li>
<li ><a href="#">Cake Bonbons</a></li>
<li ><a href="#">Holiday Cakes</a></li>
<li ><a href="#">Cakes for Girls</a></li>
<li ><a href="#">Cakes for Boys</a></li>
<li ><a href="#">For Her</a></li>
<li ><a href="#">For Him</a></li>
<li ><a href="#">Cupcakes</a></li>
</ul>
</li>
<li><a href="#">Events</a>
<ul>    
<li><a href="#">Beach Wedding</a></li>
<li><a href="#">Baby Showers</a></li>
<li><a href="#">Sweet 15-16</a></li>
</ul>
</li>
</ul>
</div><!--end of navbar-->

CSS

body {
margin:0;
font-family:Georgia, Arial black, Times, serif; 
}


h2 {
text-align:center;  
}

img {
border:none;
border:0;   
}


#topbanner {
width:100%;
height:40px;
background-color:#88C6CC;   
color:#fff;
text-align:center;
line-height:40px;
font-size:36px;
}


#container {
width:1050px;
height:800px;
background-color:#B7E6E8;
margin:auto;
position:relative;
border-radius:20px;
-moz-border-radius:20px;
-webkit-border-radius:20px;
-ms-border-radius:20px;
-o-border-radius:20px;
margin-top:10px;
}



/*Start Navigation Bar*/
#navbar ul ul {
display:none;   
}

#navbar ul li:hover > ul {
display:block;
}

#navbar ul {
background: #efefef;
background: linear-gradient(top, #efefef 0%, #bbbbbb 100%);
background: moz-linear-gradient(top, #efefef 0%, #bbbbbb 100%);
background: webkit-linear-gradient(top, #efefef 0%, #bbbbbb 100%);
box-shadow: 0px 0px 9px rgba(0,0,0,0.15);
padding: 0 40px;
border-radius:10px;
-moz-border-radius:10px;
-webkit-border-radius:10px;
list-style:none;
position:relative;
display:inline-table;
}



#navbar ul:after {
content: ""; clear: both; display: block;   
}

#navbar ul li {
float:left;
-webkit-transition:background 0.3s ease-in;
-moz-transition:background 0.3s ease-in;
-o-transition:background 0.3s ease-in;
-ms-transition:background 0.3s ease-in;
transition:background 0.3s ease-in;
}

#navbar ul li:hover {
background:#4b545f;
}


#navbar ul li:hover a {
color:#fff; 
}

#navbar ul li a {
display:block;
padding:25px 40px;
color:#757575;
text-decoration:none;   
}

#navbar ul ul {
background: #5f6975;
border-radius:0px;
-webkit-border-radius:0px;
-moz-border-radius:0px;
padding: 0;
position:absolute;
top:100%;   
width:195px;
z-index:1;
}

#navbar ul ul li {
float:none;
border-top:1px solid #6b727c;
border-bottom: 1px solid #575f6a;
position:relative;  
}

#navbar ul ul li a {
padding: 15px 40px;
color:#fff; 
}

#navbar ul ul li a:hover {
background: #4b545f;    
}

#navbar {
text-align:center;

}   

#navbar ul ul ul {
position:absolute;
left:100%;
top:0;  
width:155px;
}

1 个答案:

答案 0 :(得分:1)

你去吧。的 FIDDLE 即可。问题是将子ul显示为块。

#navbar ul li:hover > ul {
    opacity:1;
    height:auto !Important;
}
#navbar ul li:hover > ul > li {
    height:50px !important;
    opacity:1;
}
#navbar ul {
    background: #efefef;
    background: linear-gradient(top, #efefef 0%, #bbbbbb 100%);
    background: moz-linear-gradient(top, #efefef 0%, #bbbbbb 100%);
    background: webkit-linear-gradient(top, #efefef 0%, #bbbbbb 100%);
    box-shadow: 0px 0px 9px rgba(0, 0, 0, 0.15);
    padding: 0 40px;
    border-radius:10px;
    -moz-border-radius:10px;
    -webkit-border-radius:10px;
    list-style:none;
    position:relative;
    display:inline-table;
}
#navbar ul:after {
    content:"";
    clear: both;
    display: block;
}
#navbar ul li {
    float:left;
    -webkit-transition:background 0.3s ease-in;
    -moz-transition:background 0.3s ease-in;
    -o-transition:background 0.3s ease-in;
    -ms-transition:background 0.3s ease-in;
    transition:background 0.3s ease-in;
    position:relative;
}
#navbar ul li:hover {
    background:#4b545f;
}
#navbar ul li:hover a {
    color:#fff;
}
#navbar ul li a {
    display:block;
    padding:25px 40px;
    color:#757575;
    text-decoration:none;
}
#navbar ul ul {
    background: #5f6975;
    border-radius:0px;
    -webkit-border-radius:0px;
    -moz-border-radius:0px;
    padding: 0;
    position:absolute;
    top:100%;
    left:0px;
    width:195px;
    z-index:1;
    -webkit-transition:all 0.4s ease-in-out;
    transition:all 0.4s ease-in-out;
    opacity:0;
    height:0px;
}
#navbar ul ul li {
    float:none;
    border-top:1px solid #6b727c;
    border-bottom: 1px solid #575f6a;
    position:relative;
    height:0px;
    -webkit-transition:all 0.4s ease-in-out;
    transition:all 0.4s ease-in-out;
    opacity:0;
}
#navbar ul ul li a {
    padding: 15px 40px;
    color:#fff;
}
#navbar ul ul li a:hover {
    background: #4b545f;
}
#navbar {
    text-align:center;
}
#navbar ul ul ul {
    position:absolute;
    left:100%;
    top:0;
    width:155px;
}