“导航栏切换器”中的“按钮”中的其他“项目”

时间:2019-05-28 08:23:30

标签: html css bootstrap-4

创建具有许多菜单项的导航栏。导航栏将始终可见。单击导航栏按钮后,某些项目将立即显示。其他人则对导航栏保持稳定。

这是带有引导程序导航栏切换按钮的。切换按钮功能齐全,但是添加越来越多的项目会使导航栏变长。

谢谢。

    <div class="container">
        <a class="navbar-brand" href="#"><img src="img/X.png" alt="logo" style="width:40px;"></a>
        <div class="collapse navbar-collapse" id="collapsibleNavbar">
        <ul class="navbar-nav ml-auto">
            <li class="nav-item active">
                <a href="#">Home</a>
            </li>
            <li class="nav-item">
                <a href="#">Services</a>

            <li class="nav-item">
                <a href="#">Contact</a>
            </li>
            <li class="nav-item">
                <a href="#">About</a>
            </li>
        </ul>
        </div>
        <button class="btn" class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar"></button>
        <div>
            <ul>
                <li class="nav-item">
                    <a class="nav-link" href="#">Item 1</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">Item 2</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">Item 3</a>
                </li>
            </ul>
            <span class="navbar-toggler-icon"></span>
        </div>
        </div>
    </nav>

1 个答案:

答案 0 :(得分:0)

您的HTML出现了一些问题。您已将所有内容包装在按钮内。我想我得到了您想要实现的目标。看看:

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#"><img src="img/X.png" alt="logo" style="width:40px;"></a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>

  <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Services</a>

        <li class="nav-item">
          <a class="nav-link" href="#">Contact</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">About</a>
        </li>
        <li class="nav-item dropdown">
          <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
          Dropdown
        </a>
          <div class="dropdown-menu" aria-labelledby="navbarDropdown">
            <a class="dropdown-item" href="#">Item 1</a>
            <a class="dropdown-item" href="#">Item 2</a>
            <a class="dropdown-item" href="#">Item 3</a>
          </div>
        </li>
    </ul>
  </div>
</nav>