bootstrap 4导航栏导航标签

时间:2018-02-22 05:17:47

标签: twitter-bootstrap bootstrap-4

在bootstrap 4中,我尝试使用固定的底部导航栏,当点击链接时,使用的内容来自4个标签。 回到早期的引导程序,我曾经工作但试图让它与4一起工作并不适合我。有人能指出我正确的方向,我在这里找不到的东西吗?



<!DOCTYPE html>
<html lang="en">
  <head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="">
  <meta name="author" content="">
  <link rel="icon" href="../../../../favicon.ico">

  <title>Starter Template for Bootstrap</title>

  <!-- Bootstrap core CSS -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

  <!-- Custom styles for this template -->
  <style type="text/css">
      body {
          padding-top: 5rem;
      }

      .starter-template {
          padding: 3rem 1.5rem;
          text-align: center;
      }
  </style>
</head>


  <body>

    <nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-bottom">
      <a class="navbar-brand" href="#">title</a>
      <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>

      <div class="collapse navbar-collapse" id="navbarsExampleDefault">
        <ul class="navbar-nav mr-auto">
          <li class="nav-item active">
              <a class="nav-link" href="#tab1">test1</a>
          </li>
          <li class="nav-item">
             <a class="nav-link" href="#tab2" data-toggle="tab">test2</a>
          </li>
          <li class="nav-item">
             <a class="nav-link" href="#tab3" data-toggle="tab">test3</a>
          </li>
          <li class="nav-item">
             <a class="nav-link" href="#tab4" data-toggle="tab">test4</a>
          </li>
        </ul>
      </div>
    </nav>

    <main role="main" class="container">
      <h2>title</h2>
      <div class="tab-content">
        <div class="tab-pane active" id="tab1">
          <h4>test1</h4>
          tab1
        </div>
        <div class="tab-pane" id="tab2">
          <h4>test2</h4>
          tab2
        </div>
        <div class="tab-pane" id="tab3">
          <h4>test3</h4>
          tab3
        </div>
          <div class="tab-pane" id="tab4">
          <h4>test4</h4>
        </div>
      </div>
    </main>
    <!-- /.container -->
    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
  </body>
</html>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:4)

您只需在nav中添加 navbar-nav 类...

演示:https://www.codeply.com/go/IzQdCtwy78

       <ul class="navbar-nav nav mr-auto">
            <li class="nav-item active">
                <a class="nav-link" href="#tab1">test1</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#tab2" data-toggle="tab">test2</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#tab3" data-toggle="tab">test3</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#tab4" data-toggle="tab">test4</a>
            </li>
       </ul>