'subNavigation bar to the mainnavigation

I have a html file , which produces the following output

Navigation bar

Now when I click on the products, I want to show a grey subbar with horizontal options containing ProductList. sub nav bar

Similarly, if Shops are clicked, dynamically it should only show ShopList.

I have the html file for navbar.html

<!doctype html>
  <html lang="en">
    <head>
      <!-- Required meta tags -->
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">

      <!-- Bootstrap CSS -->
      <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" 
      rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">

    </head>
    <body>
      <div id="navbarFragment">
      <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
        <a class="navbar-brand" href="">BRAND</a>
        <button class="navbar-toggler" type="button" 
          data-bs-toggle="collapse" data-bs-target="#navbarTogglerDemo02" 
          aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarTogglerDemo02">
        <ul class="navbar-nav mr-auto mt-2 mt-lg-0">
            <li class="nav-item">
                <a class="nav-link" href="subnav.html#subnav">Products</a> 
            </li>
            <li class="nav-item">
                <a class="nav-link" href="">Shops</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="">Contact</a>
            </li>
        </ul>
        </div>
    </nav>
  </div>

  <div>
    
  </div>
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" 
  integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
  </body>
</html>

subnav.html

<!doctype html>
<html lang="en">
<head></head>
<body>
    <!--insert navigation bar here-->
    <div id="subnav">
        <nav id="navbar-nav ms-auto" class="navbar navbar-dark bg-light navbar-expand-lg" >
            <ul class="navbar-nav ms-auto">
               <li class="nav-item"><a href="#">Project list</a></li>></li> <!-- this has to be generic-->
               <li class="nav-item"><a href="#">About</a></li>></li>    
            </ul>
        </nav>
    </div>
</body>
</html>

Currently when I click the products, it shows the below :

output

Any guidance will be useful. PS: total beginner



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source