创建下拉菜单?我如何使用我当前的代码?

时间:2013-09-24 03:08:15

标签: html css menu html-lists

当前的html

<html>
<head>
    <link rel='stylesheet' type='text/css' href='css/styles.css' />
    <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'>    </script>
</head>
<body>
<div id='cssmenu'>
<ul>
   <li><a href='index.html'><span>Home</span></a></li>
   <li><a href='team'><span>Team</span></a>
       <ul class= "sub1">
            <li><a href='team'><span>Team</span></a>
            <li><a href='team'><span>Team2</span></a>
       </ul>
   </li>
   <li><a href='sponsors'><span>Sponsors</span></a></li>
   <li><a href='first'><span>First</span></a></li>
   <li><a href='contact-us'><span>Contact Us</span></a></li>
   <li class='last'><a href='handouts'><span>Handouts</span></a></li>
</ul>
</div>
</body>
</html>

css

#cssmenu ul {
  list-style-type: none;
  position: relative;
  display: block;
  height: 33px;
  font-size: 12px;
  background: url(../images/bg.png) repeat-x top left;
  font-family: Verdana, Helvetica, Arial, sans-serif;
  border: 1px solid #000;
  margin: 0;
  padding: 0;
  width: auto;
}
 #cssmenu li {
  display: block;
  float: left;
  margin: 0;
  padding: 0;
}
#cssmenu li a {
  float: left;
  color: #A79787;
  text-decoration: none;
  height: 24px;
  padding: 9px 15px 0;
 font-weight: normal;
}
#cssmenu li a:hover,
#cssmenu .active {
  color: #fff;
  background: url(../images/bg.png) repeat-x top left;
  text-decoration: none;
}
#cssmenu .active a {
  color: #fff;
  font-weight: 700;
}
#cssmenu ul {
  background-color: #B11718;
}
#cssmenu li a:hover,
#cssmenu li.active {
  background-color: #DE3330;
}

我尝试在线阅读有关如何执行此操作的教程,并且我听说它的隐藏然后出现在块中。

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

如果我不正确,有点像这种格式.... 任何人都可以帮助我将当前菜单变为可能的下拉菜单。我按照教程,但它不会排队O.o

请帮忙。对不起这个可怕的问题。更多的是我将如何去做。

2 个答案:

答案 0 :(得分:0)

这样的东西?

#cssmenu ul {
  list-style-type: none;
  position: relative;
  display: block;
  font-size: 12px;
  background: url(../images/bg.png) repeat-x top left;
  font-family: Verdana, Helvetica, Arial, sans-serif;
  border: 1px solid #000;
  margin: 0;
  padding: 0;
  width: auto;
}
 #cssmenu li {
  display: inline-block;
  margin: 0;
  padding: 0;
}
 #cssmenu li ul {
     position: absolute;
    display: none;
}
/* Uncomment for vertical dropdown */
/*#cssmenu li ul li {
    display: block;
}*/
 #cssmenu li:hover ul {
    display: block;
}
#cssmenu li a {
    display: block;
  color: #A79787;
  text-decoration: none;
  padding: 9px 15px;
 font-weight: normal;
}
#cssmenu li a:hover,
#cssmenu .active {
  color: #fff;
  background: url(../images/bg.png) repeat-x top left;
  text-decoration: none;
}
#cssmenu .active a {
  color: #fff;
  font-weight: 700;
}
#cssmenu ul {
  background-color: #B11718;
}
#cssmenu li a:hover,
#cssmenu li.active {
  background-color: #DE3330;
}

http://jsfiddle.net/VUpFj/1/

答案 1 :(得分:0)

将此添加到您的CSS

#cssmenu ul li ul {
  position: absolute;
  top: 33px;
  height: auto;
  margin-left: 0;
  display: none;
}
#cssmenu ul li:hover ul {
  display: block;
}
#cssmenu ul li ul li {
  display: block;
  float: left;
  clear: both;
}

并关闭<li>

内的<ul>
<ul class="sub1">
   <li><a href='team'><span>Team1</span></a></li>
   <li><a href='team'><span>Team2</span></a></li>
</ul>