javascript - href 菜单栏上的下拉按钮

标签 javascript html css

我有一个由多个链接组成的菜单栏,我想让第三个链接成为一个下拉列表。

有没有办法可以在这些 href 链接下放置一个下拉列表?我需要选项卡 3 才能有一个下拉列表,其中包含值 6 和 7。我在互联网上找不到任何其他示例。请帮忙

nav {
  position: relative;
  width: 100%;
  height: 50px;
  background-color: #34495e;
  border-radius: 8px;
  font-size: 0;
}

nav a {
  line-height: 50px;
  height: 100%;
  font-size: 15px;
  display: inline-block;
  position: relative;
  z-index: 1;
  text-decoration: none;
  text-transform: uppercase;
  text-align: center;
  color: white;
  cursor: pointer;
}

nav .animation {
  position: absolute;
  height: 100%;
  top: 0;
  z-index: 0;
  transition: all .5s ease 0s;
  border-radius: 8px;
}

a:nth-child(1) {
  width: 200px;
}

a:nth-child(2) {
  width: 200px;
}

a:nth-child(3) {
  width: 200px;
}

a:nth-child(4) {
  width: 200px;
}

a:nth-child(5) {
  width: 200px;
}

nav a:nth-child(1):hover~.animation {
  width: 200px;
  left: 0;
  background-color: #29363B;
}

nav a:nth-child(2):hover~.animation {
  width: 200px;
  left: 200px;
  background-color: #EA495F;
}

nav a:nth-child(3):hover~.animation {
  width: 200px;
  left: 400px;
  background-color: #F4837D;
}

nav a:nth-child(4):hover~.animation {
  width: 200px;
  left: 600px;
  background-color: #FAA664;
}

nav a:nth-child(5):hover~.animation {
  width: 200px;
  left: 800px;
  background-color: #99B998;
}

.active {
  border-radius: 8px;
  background-color: #29363B;
  color: white;
}
<nav>
  <a href="#" class="active" style="text-decoration: none; color: white">ONE</a>
  <a href="#" style="text-decoration: none; color: white">TWO</a>
  <a href="#" style="text-decoration: none; color: white">THREE</a>
  <a href="#" style="text-decoration: none; color: white">FOUR</a>
  <a href="#" style="text-decoration: none; color: white">FIVE</a>
  <div class="animation start-home"></div>
</nav>

最佳答案

您可以在链接内进行选择,该链接是隐藏的,直到悬停该链接。

link__dropdown {
    display: none;
}

link:hover link__dropdown {
    display: block;
}


<nav>
  <a href="#" class="active" style="text-decoration: none; color: white">ONE</a>
  <a href="#" style="text-decoration: none; color: white" class="link">TWO</a>
  <a href="#" style="text-decoration: none; color: white" class="link">
      <select class="link__dropdown">
        <option>6</option>
        <option>7</option>
      </select>
  </a>
  <a href="#" style="text-decoration: none; color: white" class="link">FOUR</a>
  <a href="#" style="text-decoration: none; color: white" class="link">FIVE</a>
  <div class="animation start-home"></div>
</nav>

关于javascript - href 菜单栏上的下拉按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57071645/

相关文章:

javascript - 如何使用服务器返回的 json 数据动态填充 google 条形图的数据

javascript - 使用 anchor 链接打开自定义 jquery 选项卡

javascript - 如何使 UI 元素可编辑?

html - 当 Bootstrap 3 出现可折叠的汉堡按钮时,你如何手动调整?

javascript 相当于 python 的编译和执行

javascript - 如何通过 File API 执行 json 文件中的数据?

javascript - ES6 类中的继承和原型(prototype)链

javascript - 我的导航栏没有保持粘性

javascript - 无法在div中显示文本框结果

html - Div 拉伸(stretch)以适应内容。溢出 : auto; does not work