Bootstrap Bootscrap NavigationBar未显示下拉菜单,全屏菜单未按预期与标题隔开

a2mppw5e  于 2023-03-16  发布在  Bootstrap
关注(0)|答案(1)|浏览(126)

代码:

<nav class="navbar navbar-expand-lg navbar-dark">
      <a class="navbar-brand" href="">tindog</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 ml-auto">
          <li class="nav-item">
              <a class="nav-link" href="">Contact</a>
          </li>
          <li class="nav-item">
              <a class="nav-link" href="">Pricing</a>
          </li>
          <li class="nav-item">
              <a class="nav-link" href="">Download</a>
          </li>
      </ul>
   </div>
  </nav>

在标题中添加了js和html的Bootscrap CDN链接:
期望值:1.根据

下面的图片,桌面上的导航栏应该是这样的间距,但我得到了这个:

1.此外,在平板电脑和手机,导航栏应该下拉菜单时,点击,但我没有,为什么?

附言:不要介意背景色。
我已经解释过了。

mbjcgjjk

mbjcgjjk1#

你忘了把bg-dark类添加到导航中。代码应该是这样的:

<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
    <div class="container-fluid">
        <a class="navbar-brand" href="">tindog</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>
 <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav ml-auto">
        <li class="nav-item">
            <a class="nav-link" href="">Contact</a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="">Pricing</a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="">Download</a>
        </li>
    </ul>
 </div>
</nav>

我也将navbar-brand封装在一个div标签中,其中包含一个名为container-fluid的类。

相关问题