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

时间:2019-05-30 15:12:36

标签: html css drop-down-menu navbar

我想知道如何在导航栏中的“社交媒体”类所在的位置添加下拉菜单。这是我的代码:

    <span class="navbar-toggler-icon"></span>
  </button>

  <div class="collapse navbar-collapse" id="navbarNavAltMarkup">
    <div class="navbar-nav">
      <a class="nav-item nav-link active" href="#">Home <span class="sr-only">(current)</span></a>
      <a class="nav-item nav-link" href="#">Social Media</a>
      <a class="nav-item nav-link" href="#">Pricing</a>
      <a class="nav-item nav-link disabled" href="#">Disabled</a>
    </div>
  </div>
</nav

1 个答案:

答案 0 :(得分:0)

<div class="navbar-nav">
<div class="dropdown">
  <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenu2" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
    Dropdown
  </button>
<div class="dropdown-menu" aria-labelledby="dropdownMenu2">
  <a class="nav-item nav-link active" href="#">Home <span class="sr-only">(current)</span></a>

  <a class="nav-item nav-link" href="#">Social Media</a>

  <a class="nav-item nav-link" href="#">Pricing</a>

  <a class="nav-item nav-link disabled" href="#">Disabled</a>
  </div>
</div>
</div>

您必须做几件事-将商品包装在2个div标签中。一种是与类下拉菜单。此按钮包含您单击以显示实际下拉菜单的按钮。另一个div是带有class下拉菜单的。该div包含您的项目。使用较新的引导程序,您可以使用按钮代替链接项。