我有一個包含在主菜單裏面的鏈接懸停在其中獲取顯示下面的主菜單的子菜單的菜單。我想要做的是在第一個子菜單中添加第二個子菜單,但使其成爲下拉菜單。我在CSS上並不是那麼棒,我想知道是否有人可以幫助我。我在網上跟着一些教程,我無法得到我期待的結果。這是迄今爲止的html和css。創建一個下拉菜單
<div id="navigation">
<ul id="mymenu">
<li><a href="#" onmouseover="javascript:showsubmenu(1)">Home</a></li>
<li><a href="#" onmouseover="javascript:showsubmenu(2)">Gallery</a></li>
<li><a href="#" onmouseover="javascript:showsubmenu(3)">What We Do</a></li>
<li><a href="#" onmouseover="javascript:showsubmenu(4)">Contact</a></li>
</ul>
</div>
<div id="sublinks">
<ul id="s1">
<li><a href="#">General</a></li>
<li><a href="#">Landon News</a></li>
<li><a href="#">Trust Us</a></li>
</ul>
<ul id="s2">
<li>
<a href="#">Security Systems</a>
<ul id="s2sys">
<li><a href="#">Arlington HA</a></li>
<li><a href="#">Enfield HA</a></li>
<li><a href="#">Revere HA</a></li>
</ul>
</li>
<li>
<a href="#">WLAN Systems</a>
<ul id="s2wlan">
<li><a href="#">Beverly HA</a></li>
<li><a href="#">Holyoke HA</a></li>
<li><a href="#">Meriden HA</a></li>
<li><a href="#">Revere HA</a></li>
</ul>
</li>
</ul>
<ul id="s3">
<li><a href="#">Computers</a></li>
<li><a href="#">Strategic Planning</a></li>
<li><a href="#">Security Systems</a></li>
<li><a href="#">WLAN, WiFi Broadband</a></li>
</ul>
<ul id="s4">
<li><a href="#">Email</a></li>
<li><a href="#">Address Info</a></li>
</ul>
</div>
這裏是主菜單將顯示第一個子菜單
function showsubmenu(id){
submenu = document.getElementById('s'+id);
for(i=1;i<=4;i++){
if(i==id){
submenu.style.display="block";
} else {
document.getElementById('s'+i).style.display="none";
}
}
}
sfHover = function() {
var sfEls = document.getElementById("sublinks").getElementsByTagName("li");
for (var i=0; i<sfEls.length; i++) {
sfEls[i].onmouseover=function() {
this.className+=" hover";
}
sfEls[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(" hover\\b"), "");
}
}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
在這裏,JavaScript是CSS
#navigation{
height:32px;
margin:0 auto;
width:auto;
}
#navigation ul{
height:32px;
line-height:32px;
}
#navigation ul li{
display:inline;
}
#navigation ul li a,
#navigation ul li a:visited {
padding:0 20px;
display:block;
text-decoration:none;
float:left;
color:#1361A5;
font-weight:bold;
text-shadow:#ffffff 2px 2px 2px;
}
#navigation ul li a:hover{
color:#C3C2C1;
}
/* ----------- Sub Menu ----------- */
#sublinks{
width:auto;
margin:0 auto;
background:#C3C2C1;
height:30px;
font-size:11px;
border-radius:8px;
-moz-border-radius:8px; /* Firefox 3.6 and earlier */
-webkit-border-radius: 8px;
-webkit-box-shadow: 0 2px 3px rgba(136, 136, 136, 1);
-moz-box-shadow: 0 2px 3px rgba(136, 136, 136, 1);
box-shadow: 0 2px 3px rgba(136, 136, 136, 1);
behavior: url(http://localhost/landon/assets/pie/PIE.php);
position: relative;
}
#sublinks ul{
height:32px;
line-height:31px;
}
#sublinks ul li{
display:inline;
}
#sublinks ul li a,
#sublinks ul li a:visited {
padding:0 10px;
display:block;
text-decoration:none;
float:left;
color:#FFFFFF;
}
#sublinks ul li a:hover{
text-decoration:underline;
}
#sublinks li:hover ul{
display: block;
position: absolute;
margin: 0;
padding: 0;
}
#sublinks li:hover li {
float: none;
}
#sublinks li:hover li a {
background-color: #C3C2C1;
border-bottom: 1px solid #fff;
color: #000;
left:50;
}
#sublinks li li a:hover {
background-color: #8db3ff;
}
/* ----------- Hide Sub menu ----------- */
#s2, #s3, #s2sys, #s2wlan{display:none;}
我所試圖做的是使第二子從第一個子菜單下拉菜單,此時它顯示在同一行內,而不是下拉菜單。我怎樣才能做到這一點?
請問您可以創建[JsFiddle](http://jsfiddle.net/) – Aymeric
小提琴:http://jsfiddle.net/Hxduu/1/ – worenga
以下是JsFiddle的鏈接:jsfiddle.net/4k2Tx/ –