Home > database >  something wrong with the navbar
something wrong with the navbar

Time:12-19

i have a problem with the navbar it works fine on full width but when i shrink the page the menu button appears and all but it is not working and i can't seem to figure out where is the problem is located in my code

<nav id="mainNavbar" > 
  <a href="#" >CANDY</a>
  <button  type="button" data-bs-toggle="collapse" data-bs-target="#navLinks">
    <span ></span>
  </button>
  <div id="navLinks" >
    <ul >
     <li >
      <a href="#" >Home</a>
     </li>
     <li >
      <a href="#" >About</a>
     </li>
     <li >
      <a href="#" >Tickets</a>
     </li>
     
    </ul>
  </div>
</nav>

<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X 965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH 8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV 2 9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3 MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>

CodePudding user response:

You're mixing HTML Markup for Bootstrap 5 and importing Bootstrap 4.1.3. One of the key differences is:

Bootstrap 5 (As per your code): <button type="button" data-bs-toggle="collapse" data-bs-target="#navLinks">

Bootstrap 4: <button type="button" data-toggle="collapse" data-target="#navLinks">

Two options:

  1. Change your HTML to the HTML markup for a navbar as per https://getbootstrap.com/docs/4.1/components/navbar/
  2. Change your bootstrap imports to Bootstrap 5 (preferred):
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP JcXn/tWtIaxVXM" crossorigin="anonymous"></script>

CodePudding user response:

Have you included the css link? You may also modify the top javascript bootstrap link by doing something like this.

<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3 MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X 965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH 8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV 2 9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
  • Related