0

I am creating a web, which will have many sub pages and I want to include a NavBar in all of them, I am working with bootstrap 5 and I want to know if there is any way to create a single NavBar and insert it in all the pages so I don't have to update them 1 by one every time I make a change.

I leave here the code of my NavBar:

<html lang="es">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>ALCOHOLIMPIADAS</title>
    <link rel="shortcut icon" href="../img/icono.png">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.3/font/bootstrap-icons.css">
  </head>
  <body>
    <!--MENU-->
    <nav class="navbar navbar-expand-lg bg-body-tertiary">
      <div class="container-fluid">
        <a class="navbar-brand" href="../index.html">
          <img src="../img/logo.png" alt="Logo" width="70" height="70" class="d-inline-block"> ALCOHOLIMPIADAS </a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
          <ul class="navbar-nav">
            <li class="nav-item">
              <a class="nav-link active" aria-current="page" href="../index.html">INICIO</a>
            </li>
            <li class="nav-item dropdown">
              <a class="nav-link dropdown-toggle" href="../#" role="button" data-bs-toggle="dropdown" aria-expanded="false"> JUEGOS </a>
              <ul class="dropdown-menu">
                <li>
                  <a class="dropdown-item" href="../juegos_cartas.html">JUEGOS CON CARTAS</a>
                </li>
                <li>
                  <a class="dropdown-item" href="../juegos_nada.html">JUEGOS SIN NADA</a>
                </li>
                <li>
                  <a class="dropdown-item" href="../#">JUEGOS DE DADOS</a>
                </li>
              </ul>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="../#">CONTACTO</a>
            </li>
          </ul>
        </div>
      </div>
    </nav>
      </body>
</html>

I have tried to import the code from another file with JavaScript but the format is not correct. I have already checked these links but I have not been able to make it work: SO (in spanish) Lost question

Aarón Rojas
  • 103
  • 3
  • u using a precompiler? then maybe use a template langauge. or else you can create a web component – Sysix Feb 16 '23 at 19:38

0 Answers0