Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bootstrap 4 navbar to navigate tabs

In bootstrap 4 I am attempting to use a fixed bottom navbar that when the links are clicked the content that's used is from 4 tabs. Back in the early days of bootstrap what I had worked but trying to get it to work with 4 is not working for me. Can someone point me in the right direction on what I am missing here please?

<!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>
like image 959
midlifecrisis Avatar asked Feb 22 '18 05:02

midlifecrisis


1 Answers

You just need to include the nav class in the navbar-nav...

Demo: 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>
like image 137
Zim Avatar answered Oct 07 '22 02:10

Zim