html - Bootstrap导航栏布局错误

标签 html css twitter-bootstrap navbar

我的导航栏应该看起来像顶部的导航栏,但是它会在其下方输出混乱信息:

.

我该如何解决?

这是我的html文件中的代码:

   <nav class="navbar navbar-expand-lg navbar-dark bg-light">
    <a class="navbar-brand" href="#">Navbar</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>
    <a class="nav-link" href="#">Home <span class="sr-only">(current) 
    </span></a>
  </li>
  <li class="nav-item">
    <a class="nav-link" href="#">Link</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="#">Action</a>
      <a class="dropdown-item" href="#">Another action</a>
      <div class="dropdown-divider"></div>
      <a class="dropdown-item" href="#">Something else here</a>
   </div>
   </li>
   <li class="nav-item">
    <a class="nav-link disabled" href="#">Disabled</a>
   </li>
  </ul>
 </div>
</nav>

最佳答案

您的代码已分离并损坏,对于主要的navbar类,应将其

navbar-light bg-light




navbar-dark bg-light


请阅读documentation了解如何使用Bootstrap。

工作导航栏示例:



<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">Navbar</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>
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Link</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="#">Action</a>
          <a class="dropdown-item" href="#">Another action</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="#">Something else here</a>
        </div>
      </li>
      <li class="nav-item">
        <a class="nav-link disabled" href="#">Disabled</a>
      </li>
    </ul>
  </div>
</nav>

关于html - Bootstrap导航栏布局错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50282056/

相关文章:

javascript - 使用JavaScript更改CSS

javascript - 调整窗口大小时,页面上的四个图像不会调整大小

jquery - html元素隐藏在另一个元素后面

javascript - 使用 jquery Trigger 功能切换所有复选框

jquery - 如何使用 jQuery 在页面加载时打开 Accordion 风格的网格?

jquery - jQuery $('selector')。css('top')返回IE,firefox和Chrome的不同值

css - 将容器 div 放在另一个容器上( Bootstrap )

javascript - 如何使用谷歌地图标记地点

javascript - 在我的窗口屏幕之外停止动画

css - 使用 Clojure Hiccup 呈现样式信息的惯用方式