【问题标题】:Drop down menu on hover the navigation bar?悬停在导航栏上的下拉菜单?
【发布时间】:2016-01-07 05:00:31
【问题描述】:

我想创建一个像这个网站http://www.jamieoliver.com/ 这样的下拉菜单。 要查看下拉菜单,只需将导航栏悬停在此 http://www.jamieoliver.com/ 网站上

【问题讨论】:

  • 请在询问之前自己尝试一下。显示一些你尝试过的代码,然后一些可以帮助你

标签: javascript jquery html css angularjs


【解决方案1】:

你应该看到这个问题:

Bootstrap Dropdown with Hover

How to make twitter bootstrap menu dropdown on hover rather than click,

无论如何,您应该提供一些代码或一些您在询问之前做过的尝试,就像@Chris Beckett 所说的那样。

【讨论】:

  • 这实际上是一个评论,而不是一个答案。我很感激您可能还没有足够的声誉来离开 cmets,但请不要使用答案系统作为替代品。获得声誉相当容易,只需要您付出一点努力。谢谢!
  • 非常感谢您了解我的情况@Paulie_D!
【解决方案2】:

这里有一个简单的示例供您查看。将来,请在此处提问之前尝试自己尝试执行此操作。这样一来,在有人用勺子递给你之前,你至少已经尝试过了。

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:

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

【讨论】:

  • 谢谢贝克特兄弟。实际上我是一个新手,我对前端开发没有太多了解。感谢您的帮助。
  • 我还想问一个问题?我想在单击下拉菜单下的链接时隐藏下拉菜单
  • @Mubashir 你能解释一下你想要什么,我可以帮你吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-23
  • 2019-04-19
  • 1970-01-01
  • 2013-02-01
  • 1970-01-01
相关资源
最近更新 更多