无法在 Bootstrap 中获取水平 'Navbar'

Couldn't get the horizontal 'Navbar' in Bootstrap

如何使这个 bootstrap 'Navbar' 变直,我尝试使用不同的导航栏 类 但无法变直,请帮助我。此处给出的网页快照 web-page snapshot

    <!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
    <meta charset="utf-8">
    <title>>Bootstrap Practice</title>

  </head>
  <body>

<!-- Navbars -->
    <nav class="navbar navbar-default">

      <div class="container">
        <div class="navbar-header">
         <a href="https://www.youtube.com/user/ColdplayVEVO" class="navbar-brand">Coldplay</a>
       </div>

       <ul class="nav navbar-nav">
         <li> <a href="">Albums</a> </li>
         <li> <a href="#">Awards</a> </li>
         <li> <a href="#">Legacy</a> </li>
         <li> <a href="#">About</a> </li>
       </ul>

      </div>

     </nav>
  </body>
</html>

navbar-nav 的默认行为是

flex-direction: column;

在html

中设置一个class
<ul class="nav navbar-nav navigation-bar-row">
    <li> <a href="">Albums</a> </li>
    <li> <a href="#">Awards</a> </li>
    <li> <a href="#">Legacy</a> </li>
    <li> <a href="#">About</a> </li>
</ul>

然后在你的 css:

.navigation-bar-row {
    flex-direction: row;
}

如果你像我一样懒惰,请跳过上面的所有内容,然后执行:

<ul class="nav navbar-nav" style="flex-direction: row;">
    <li> <a href="">Albums</a> </li>
    <li> <a href="#">Awards</a> </li>
    <li> <a href="#">Legacy</a> </li>
    <li> <a href="#">About</a> </li>
</ul>

编辑:我楼下的评论说的对。最好的办法是将 "d-flex flew-row" 添加到 ul class 列表中。

Bootstrap Navbar docs 有一个工作示例,您可以复制和粘贴,根据需要替换为您自己的值。

<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 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="#">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="#" tabindex="-1" aria-disabled="true">Disabled</a>
      </li>
    </ul>
    <form class="form-inline my-2 my-lg-0">
      <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
      <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
    </form>
  </div>
</nav>

在 Bootstrap 4 中设置了 类,这会将 'horizontal' 导航转换为垂直导航。都是直男

(function(){
 var menuToggle = $('#menu-toggle');
 menuToggle.click(function(){
  menuToggle.next().toggleClass('d-sm-block');
  menuToggle.next().toggleClass('d-none');
 });
})();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-expand-sm bg-light">
 <!-- PUT A BUTTON HERE THAT ON CLICK WILL SHOW HIDE THE NAV -->
 <button id="menu-toggle" class="d-block d-md-none">Menu *burger icon*</button>
 <ul class="navbar-nav d-none d-md-inline-flex">
  <li class="nav-item">
   <a class="nav-link" href="#">Link 1</a>
  </li>
  <li class="nav-item">
   <a class="nav-link" href="#">Link 2</a>
  </li>
  <li class="nav-item">
   <a class="nav-link" href="#">Link 3</a>
  </li>
 </ul>
</nav>
<br>

<div class="container-fluid">
 <h3>Basic Navbar Example</h3>
 <p>A navigation bar is a navigation header that is placed at the top of the page.</p>
 <p>The navbar-expand-xl|lg|md|sm class determines when the navbar should stack vertically (on extra large, large, medium or small screens).</p>
</div>

您也可以在其中放置一个按钮来切换导航。再次使用 Bootstrap 类.

我没有太长的时间,所以这是我得到的。