Search code examples
htmlcssdeploymentbootstrap-5responsiveness

How to move elements to the ends and make the hamburger button work? [ HTML & Bootstrap ]


I am making a navbar for a website and I want to move the header and the link to the ends of the navbar. Also, when I shorten the site's width, the hamburger button appears but does not display the links and is not alignes properly. I am using HTML and Bootstrap

This is how it looks on desktop : Screenshort of the page on desktop

and this is how it looks on mobile and tablets : enter image description here

Any help is greatly appreciate it!

This is my current code. NOTE: I have linked the Bootstrap CSS files in the head tag and the script tag just before the /body tag.

<div class="container">
      <nav class="navbar navbar-expand-lg">
        <div class="container">
          <header
            class="d-flex flex-wrap justify-content-center align-items-center py-3">
            <h2>
              <a href="/" class="text-decoration-none link-dark">CAFÉ - 82</a>
            </h2>
          </header>
          <button
            class="navbar-toggler"
            type="button"
            data-bs-toggle="collapse"
            data-bs-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent"
            aria-expanded="false"
            aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
          </button>
          <div class="collapse navbar-collapse" id="#navbarSupportedContent">
            <ul class="navbar-nav pb-2">
              <li class="nav-item">
                <a class="nav-link active" aria-current="page" href="#">Menu</a>
              </li>
              <li class="nav-item">
                <a class="nav-link" href="#">About</a>
              </li>
              <li class="nav-item">
                <a class="nav-link" href="#">Contact</a>
              </li>
            </ul>
          </div>
        </div>
      </nav>
    </div>

Solution

  • The alignment is not reproducible with the given sample. However, the hamburger isn't showing the menu when clicked because you have a hashtag / pound / # in the id value.

    <div class="collapse navbar-collapse" id="#navbarSupportedContent">
    

    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous">
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz" crossorigin="anonymous"></script>
    
    <div class="container">
      <nav class="navbar navbar-expand-lg">
        <div class="container">
          <header
            class="d-flex flex-wrap justify-content-center align-items-center py-3">
            <h2>
              <a href="/" class="text-decoration-none link-dark">CAFÉ - 82</a>
            </h2>
          </header>
          <button
            class="navbar-toggler"
            type="button"
            data-bs-toggle="collapse"
            data-bs-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent"
            aria-expanded="false"
            aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
          </button>
          <div class="collapse navbar-collapse" id="navbarSupportedContent">
            <ul class="navbar-nav pb-2">
              <li class="nav-item">
                <a class="nav-link active" aria-current="page" href="#">Menu</a>
              </li>
              <li class="nav-item">
                <a class="nav-link" href="#">About</a>
              </li>
              <li class="nav-item">
                <a class="nav-link" href="#">Contact</a>
              </li>
            </ul>
          </div>
        </div>
      </nav>
    </div>