简体   繁体   English

悬停在导航栏上的下拉菜单?

[英]Drop down menu on hover the navigation bar?

I want to create a drop down menu like this website http://www.jamieoliver.com/ . 我想创建一个类似于此网站http://www.jamieoliver.com/的下拉菜单。 To see the drop down menu, just hover the navigation bar on this http://www.jamieoliver.com/ website 要查看下拉菜单,只需将鼠标悬停在此http://www.jamieoliver.com/网站上

You should see this questions: 您应该看到以下问题:

Bootstrap Dropdown with Hover 带悬停的Bootstrap下拉菜单

How to make twitter bootstrap menu dropdown on hover rather than click , 如何在悬停而不是单击上使twitter引导菜单下拉菜单

Anyway, you should have provided some code or some tries you have done before asking as @Chris Beckett said. 无论如何,在询问@Chris Beckett之前,您应该已经提供了一些代码或进行了一些尝试。

Here a quick example for you to have a look at. 这里有个快速的例子供您查看。 In the future please try and attempt to do this yourself before asking a question on here. 将来,请先尝试自己尝试执行此操作,然后再在此处提出问题。 That way least you've given it a go before someone has handed you it on a spoon. 这样一来,至少在某人将它递到勺子上之前,您已经放手了。

HTML: HTML:

  <body class="news">
  <header>
    <div class="nav">
      <ul>
        <li class="home"><a href="#">Home</a></li>
        <li class="tutorials"><a href="#">Tutorials</a>
          <ul>
            <li><a href="#">Tutorial</a></li>
            <li><a href="#">Tutorial2</a></li>
            <li><a href="#">Tutorial3</a></li>
          </ul>
        </li>
        <li class="about"><a class="active" href="#">About</a></li>
        <li class="news"><a href="#">Newsletter</a>
          <ul>
            <li><a href="#">News1</a></li>
            <li><a href="#">News2</a></li>
            <li><a href="#">News3</a></li>
          </ul>
        </li>
        <li class="contact"><a href="#">Contact</a></li>
      </ul>
    </div>
  </header>
</body>

CSS: CSS:

body {
  margin: 0;
  padding: 0;
  background: #ccc;
}

.nav ul {
  list-style: none;
  background-color: #444;
  text-align: center;
  padding: 0;
  margin: 0;
}

.nav li {
  font-family: 'Oswald', sans-serif;
  font-size: 1.2em;
  line-height: 40px;
  text-align: left;
}

.nav a {
  text-decoration: none;
  color: #fff;
  display: block;
  padding-left: 15px;
  border-bottom: 1px solid #888;
  transition: .3s background-color;
}

.nav a:hover {
  background-color: #005f5f;
}

.nav a.active {
  background-color: #aaa;
  color: #444;
  cursor: default;
}

/* Sub Menus */
.nav li li {
  font-size: .8em;
}

/*******************************************
   Style menu for larger screens

   Using 650px (130px each * 5 items), but ems
   or other values could be used depending on other factors
********************************************/

@media screen and (min-width: 650px) {
  .nav li {
    width: 130px;
    border-bottom: none;
    height: 50px;
    line-height: 50px;
    font-size: 1.4em;
    display: inline-block;
    margin-right: -4px;
  }

  .nav a {
    border-bottom: none;
  }

  .nav > ul > li {
    text-align: center;
  }

  .nav > ul > li > a {
    padding-left: 0;
  }

  /* Sub Menus */
  .nav li ul {
    position: absolute;
    display: none;
    left: 0;
    width: 100%;
    height: 400px;
    background-color: grey;
  }

  .nav li:hover ul {
    display: block;
  }

  .nav li ul li {
    float: left;
    width: 20%;
  }
}

JSFIDDLE EXAMPLE JSFIDDLE示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM