The hamburger icon on the Bootstrap 4 navbar expands as expected, yet it fails to collapse back when

<head>
<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>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Poppins">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

/* I attempted to align the logo to the far left, home and about in the center, and log in to the right. I achieved this layout, but the hamburger menu does not function correctly in mobile view. It expands but does not collapse */

<body>
<nav class="navbar navbar-expand-md navbar-light bg-white shadow-sm nav-font">
    <div class="container">
        <a href="#">
            <img src="/storage/img/msprojectlogo.png" style="width:30%;">
        </a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="{{ __('Toggle navigation') }}">
            <span class="navbar-toggler-icon"></span>
        </button>

        <div class="collapse navbar-collapse justify-content-md-center" id="navbarSupportedContent">
            <!-- Left Side Of Navbar -->
            <ul class="navbar-nav ml-auto">
                <li class="nav-item p-1 pl-4"><a class="nav-link" href="/">Home</a></li>
                <li class="nav-item p-1 pl-4"><a class="nav-link" href="/about">About</a></li>
                <li class="nav-item p-1 pl-4"><a class="nav-link" href="/services">Services</a></li>
                <li class="nav-item p-1 pl-4"><a class="nav-link" href="/posts">Blog</a></li>
            </ul>
            <!-- Right Side Of Navbar -->
            <ul class="navbar-nav ml-auto">
                <li class="nav-item p-1 pl-4">
                    <a class="nav-link" href="#') }}</a>
                </li>
                <li class="nav-item p-1 pl-4">
                    <a class="nav-link" href="#</a>
                </li>
            </ul>
        </div>
    </div>
</nav>

Answer №1

Success,

Include Bootstrap CSS CDN

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<head>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  <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>
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Poppins">
</head>

<body>

  <nav class="navbar navbar-expand-md navbar-dark bg-dark shadow-sm nav-font">
      <div class="container">
          <a href="#">
              <img src="https://i.sstatic.net/q2xkQ.png" style="width:50%;">
          </a>
          <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="{{ __('Toggle navigation') }}">
              <span class="navbar-toggler-icon"></span>
          </button>

          <div class="collapse navbar-collapse justify-content-md-center" id="navbarSupportedContent">
              <!-- Left Side Of Navbar -->
              <ul class="navbar-nav ml-auto">
                  <li class="nav-item p-1 pl-4"><a class="nav-link" href="/">Home</a></li>
                  <li class="nav-item p-1 pl-4"><a class="nav-link" href="/about">About</a></li>
                  <li class="nav-item p-1 pl-4"><a class="nav-link" href="/services">Services</a></li>
                  <li class="nav-item p-1 pl-4"><a class="nav-link" href="/posts">Blog</a></li>
              </ul>
              <!-- Right Side Of Navbar -->
              <ul class="navbar-nav ml-auto">
                  <li class="nav-item p-1 pl-4">
                      <a class="nav-link" href="#') }}</a>
                  </li>
                  <li class="nav-item p-1 pl-4">
                      <a class="nav-link" href="#</a>
                  </li>
              </ul>
          </div>
      </div>
  </nav>
</body>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I'm feeling a bit lost on how to bring my random quote generator to life

I'm attempting to add animation to my random quote generator by making it look like another card is being flipped on top of the existing one, similar to a deck of cards. With limited coding knowledge, I followed a tutorial and made some adjustments to ...

Alert: The attempt to include_once(headerSite.php) has encountered an error as the file does not exist in the specified directory

I'm a beginner in PHP and encountering the following errors: Warning: include_once(headerSite.php): failed to open stream: No such file or directory in C:\xampp\htdocs\dbtest\index.php on line 3 Warning: include_once(): Failed ope ...

If a quote character is detected in a string, color the line red

My goal is to highlight each line from a string in red if it contains the ">" character. I am applying this logic to a database query result, and while it's successful, I'm encountering an issue where an HTML line break is inserted after each ...

CSS3 Internet Explorer 10 Page Fade-In Transition Effect

Seeking a sleek, elegant lightweight CSS3 page fade-in transition effect. Requirement only for IE 10 compatibility, as I plan to implement it in a Windows Metro App using the WebView control (a lightweight browser control based on IE 10). Transition shou ...

What purpose does the "invert" attribute serve on an HTML tag?

Recently, I came across something intriguing in the YouTube html source code: <!doctype html><html invert style=... Can anyone enlighten me on the purpose of the invert attribute in this code? ...

When an image is loaded, use Jquery to automatically open a new tab, instead of

I need to implement a function where, on loading an image on a page, a new tab opens and starts downloading a file from a specific URL while keeping the original page open. This task is part of a WordPress site with a jQuery section in the backend. I' ...

What is the best way to use jQuery to update the color of an SVG shape?

Hello everyone! I'm excited to be a part of this community and looking forward to contributing in the future. But first, I could really use some assistance with what seems like a simple task! My focus has always been on web design, particularly HTML ...

Changing the designated materialUI class

Within the project, I am utilizing this theme: export const theme = createMuiTheme({ ...defaultThemeConfig, overrides: { ...defaultThemeConfig.overrides, MuiListItem: { root: { '&:nth-child(odd)': { backgro ...

Implement Clip Function with Gradient Effect in JavaScript on Canvas

Trying to incorporate the clip() function within the canvas element to create a unique effect, similar to the one shown in the image. I have successfully achieved a circular clip, but I am now aiming for a gradient effect as seen in the example. How can th ...

Animate the centering of a DIV

Currently, I am working on an animation featuring a series of DIV's contained within a div with the identifier id="wrapper", all styled using CSS3. However, when I hover over the rounded box, the animation is not properly aligned in the center. You ca ...

In search of the HTML code for the forward button when extracting content from a webpage

While using Power Automate Desktop to scrape a webpage, I encountered an issue with clicking the next button. Even after copying the HTML code within the developer tools of the webpage, I found that both the previous and next buttons had the same path, mak ...

I am encountering a 404 error when attempting to make a GET request for a file located in the same directory

Here is the Javascript code that utilizes the get method. The directory contains both files - the HTML file where the JS code resides, and the text file. Below is an image of the console displaying errors. ...

Is there a way to adjust the transparency of individual words in text as you scroll down a page, similar to the effect on https://joincly

Is there a way to achieve a text filling effect on page scroll similar to the one found here: . The specific section reads: "Deepen customer relationships. Own the brand experience. Add high margin revenue. Manage it all in one place. Get back your pr ...

The navigation icon on my website refuses to close

Hey there, I'm having some trouble creating a side navigation menu. The issue I am facing is that the menu opens without any problem, but then I can't seem to figure out how to close it using a second "onclick()" function. If you could take a lo ...

The collapsible toggle menu fails to collapse on mobile-sized screens

I've experimented with basic Bootstrap in order to create a toggle menu, but I'm encountering issues. The menu collapses instead of expanding when the screen size is maximized ('m'). Furthermore, clicking on the toggle icon does not cau ...

What is preventing HTML from triggering JavaScript when loaded inside a <div> with a script?

I'm working on creating a collapsible menu that I can easily customize on any page without the use of iframes. As someone new to web design, I have knowledge of CSS and HTML but I am currently learning JavaScript with limited experience in jQuery or A ...

Applying Media Queries Based on Element Height

Situation: In my scenario, there is an image with two buttons below it, all of which share the same width. Issue: When the viewport is too wide horizontally, the buttons are not visible without scrolling down. This poses a challenge for tablets and small ...

IE6 is not displaying the tag styles correctly

My website has a section that shows two links next to each other. While it's displaying correctly on most browsers, it seems to have issues specifically in IE6. You can view the issue on this fiddle. Can anyone shed some light on why this is happenin ...

What could be causing the load() function in my AJAX to not work properly in this code?

I am trying to implement a script that loads a navigation menu (ul element) from one HTML page to a specific div on another page. The ul element has a unique id, and I am using this id to load only the ul element and not the entire HTML page it is a part ...

Switch out HTML tags depending on attribute content

In my current project, I am looking to replace all instances of the vanilla <a> tag with a different tag (<router-link>). The challenge lies in applying certain conditions based on the value of the href attribute (for example, it should ignore ...