如何在此导航栏中添加下拉菜单?

时间:2010-12-24 15:38:56

标签: html css

嘿伙计们,我创建了一个导航栏,我想知道我是否可以为娱乐选项卡创建一个下拉菜单,以提供两个链接,音乐和电影。你能帮忙吗?

这是导航栏:

<div class="navbar">
  <ul class="navbar">
  <li class="navbar"><a class="navbar" HREF="index.php">Homepage</a></li>
  <li class="navbar"><a class="navbar" HREF="classes.php">Classes</a></li>
  <li class="navbar"><a class="navbar" HREF="calendar.php">Calendar</a></li>
  <li class="navbar"><a class="navbar" HREF="news.php"  >News</a></li>
  <li class="navbar"><a class="navbar" HREF="creative.php" >Creativity</a></li>
  <li class="navbar"><a class="navbar" HREF="groups.php" >Groups</a></li>
  <li class="navbar"><a class="navbar" HREF="entertainment.php" >Entertainment</a></li>
  <li class="navbar"><a class="navbar" HREF="aboutus.php" >About Us</a></li>
  </div>

这是navbar类的css:

ul.navbar
{
list-style-type:none;
margin:0;
padding:0;
overflow:hidden;
}
li.navbar
{
float:left;
}
a.navbar:link,a.navbar:visited
{
display:block;
width:143px;
font-weight:bold;
color:white;
background-color:#98bf21;
text-align:center;
padding:4px;
text-decoration:none;
text-transform:uppercase;
}
a.navbar:hover,a.navbar:active
{
background-color:#7A991A;
}

3 个答案:

答案 0 :(得分:0)

一种经典的方式是Suckerfish dropdowns(没有javascript)

答案 1 :(得分:0)

看看这里: http://jsfiddle.net/qHKbc/2/

当您使用类.menu-header

滚动元素时,jquery显示并隐藏下一个子菜单
    $('.menu-header').hover(
      function() { $('ul', this).stop(true, true).slideToggle(100); },
      function() { $('ul', this).stop(true, true).slideToggle(100);  }
    );

子菜单隐藏了css

ul#navbar li ul.sub-menu { display:none; position:absolute; z-index: 100; }

我会研究使用jQuery插件hoverIntent。

答案 2 :(得分:0)

这是一个没有javascript的示例http://jsfiddle.net/huhu/KZchD/

#access {
    padding:0;
    margin:0;
    background: #98bf21;
    display: block;
    float: left;
    margin: 0 auto;
    width: 700px;
}
#access .menu {
    font-size: 13px;
    margin-left: 12px;
    width: 928px;
}
#access .menu ul {
    list-style: none;
    padding:0;
    margin:0;
}
#access .menu li {
    float: left;
    position: relative;
}
#access a {
    color: #fff;
    display: block;
    line-height: 38px;
    padding: 0 10px;
    text-decoration: none;
}
#access ul ul {
    display: none;
    position: absolute;
    top: 38px;
    left: 0;
    float: left;
    width: 180px;
    z-index: 99999;
}
#access ul ul li {
    min-width: 180px;
}
#access ul ul ul {
    left: 100%;
    top: 0;
}
#access ul ul a {
    background: #7A991A;
    line-height: 1em;
    padding: 10px;
    width: 160px;
    height: auto;
}
#access li:hover > a, #access ul ul :hover > a {
    background: #7A991A;
    color: #fff;
}
#access ul li:hover > ul {
    display: block;
}
<div id="access">
  <div class="menu">
    <ul>
      <li><a href="index.php">Homepage</a></li>
      <li><a href="classes.php">Classes</a></li>
      <li><a href="calendar.php">Calendar</a></li>
      <li><a href="news.php">News</a></li>
      <li><a href="creative.php">Creativity</a></li>
      <li><a href="groups.php">Groups</a></li>
      <li><a href="entertainment.php">Entertainment</a>
        <ul>
          <li><a href="music.php">Music</a></li>
          <li><a href="movies.php">Movies</a></li>
        </ul>
      </li>
      <li><a href="aboutus.php">About Us</a></li>
    </ul>
  </div>
</div>