The Bootstrap navigation bar toggle is malfunctioning and cannot expand as intended

I've been struggling with my navigation bar built using HTML, CSS, and Bootstrap. Despite following tutorials on YouTube, I can't seem to get the toggle button to expand when the screen size is reduced to the smallest. Starting a new project, I implemented all of this with HTML, CSS, and Bootstrap, and opened the HTML file locally. Could you please help me? I've been stuck for hours.

Here are the codes I used:

<head>
    <meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <meta http-equiv="X-UA-Compatible" content="ie=edge"/>
    <script src="https://code.jquery.com/jquery-3.5.1.js"></script>
    <link rel="stylesheet" href="bootstrap.min.css"/>
    <link rel="stylesheet" href="title.css" />
    <title>Document</title>
</head>
<body>
   <nav class="navbar navbar-expand-md navbar-light bg-light sticky-top">
     <button class="navbar-toggler" data-toggle="collapse" data-target="#collapse_target">
       <span class="navbar-toggler-icon></span>
     </button>

     <div class="collapse navbar-collapse" id="collapse_target">
       <a class="navbar-brand>Logo</a>

       <ul class="navbar-nav">
         <li class="nav-item">
           <a class="nav-link href="#">Link 1</a>
         </li>
         <li class="nav-item">
           <a class="nav-link href="#">Link 2</a>
         </li>
         <li class="nav-item">
           <a class="nav-link href="#">Link 3</a>
         </li>
      </ul>
    </div>
   </nav>
</body>

My current result looks like this:

https://i.sstatic.net/g26eX.png

I see the toggler icon but am unable to click it to access 'Home', 'Categories', 'About' or 'Contact'. Can you point out where I might have gone wrong?

Thank you for your assistance.

Answer №1

You may have overlooked JS, as their CDN can be found on getbootstrap.com I have included two responsive navbars below. The code for these navbars was sourced from getbootstrap.com

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

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="42202d2d36313630233202766c776c71">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">

    <title>Document</title>
  </head>
  <body>
    <nav class="navbar navbar-expand-sm navbar-dark bg-dark">
  <a class="navbar-brand" href="#">Expand at sm</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExample03" aria-controls="navbarsExample03" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>

...
   /* Remaining HTML code here */
  
   <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
   <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ceaca1a1babdbabcafbe8efae0fbe0fd">[email protected]</a>/dist/js/bootstrap.min.js" integrity="sha384-w1Q4orYjBQndcko6MimVbzY0tgp4pWB4lZ7lr30WKz0vr/aWKhXdBNmNb5D92v7s" crossorigin="anonymous"></script>

  </body>
</html>

Answer №2

In order for Bootstrap to work properly, it relies on JavaScript. It is important to include the necessary scripts that Bootstrap requires. You can find more information at this source: https://getbootstrap.com/docs/4.5/getting-started/introduction/#js

<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d2b0bdbda6a1a6a0b3a292e6fce7fce1">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous"gt;</script>

Answer №3

Seems like the "type: button" attribute is absent in your current button tag. Take a look at the code snippet below for reference:

<button class="toggle-navbar" type="button" data-toggle="collapse" data-target="#target_collapse">

Answer №4

Having an issue with your JavaScript code? Make sure to include Boostrap JS in your script.
Simply add the following code snippet to your webpage.

Example:

<html>
<head>
  <meta charset="UTF-8"/>
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  <meta http-equiv="X-UA-Compatible" content="ie=edge"/>
  <script src="https://code.jquery.com/jquery-3.5.1.js"></script>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css"/>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js"></script>
  <title>Document</title>
</head>
<body>
  <nav class="navbar navbar-expand-lg navbar-light bg-light container">
    <a class="navbar-brand" href="#">Boostrap</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" id="navbarSupportedContent">
      <ul class="navbar-nav mr-auto">
        <li class="nav-item active">
          <a class="nav-link" href="#">Now<span class="sr-only">(current)</span></a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Can</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Use</a>
        </li>
        <li class="nav-item dropdown">
          <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
            Dropdown
          </a>
          <div class="dropdown-menu" aria-labelledby="navbarDropdown">
            <a class="dropdown-item" href="#">Action</a>
            <a class="dropdown-item" href="#">Another action</a>
            <div class="dropdown-divider"></div>
            <a class="dropdown-item" href="#">Something else here</a>
          </div>
        </li>
        <li class="nav-item">
          <a class="nav-link disabled" href="#">Donate Me</a>
        </li>
      </ul>
      <form class="form-inline my-2 my-lg-0">
        <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
        <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Searching</button>
      </form>
    </div>
  </nav>
</body>
</html>

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

State in Angular stubbornly refuses to switch despite condition changes

Here is the Typescript code, followed by the HTML: public verifySelection() { let choice = false; if (typeof this.formUser.permissionsTemplateID === undefined) { choice = true; } return choice; } <div class="form-group" ...

No reaction being triggered by the CSS Media Query

I'm attempting to have the title-image stay static when the screen size is below 1052px so that it fills the full width of the viewport, but the styles should only be applied when the screen size is less than 992px. This is from the Web Development co ...

Launch a dialogue box by clicking on the buttons corresponding to the article ID

I am currently in the process of setting up an admin panel with some quick actions for managing my articles, such as deleting them. When I click on the trash can icon, a dialog box should open and prompt me to confirm the deletion. This dialog box should b ...

Image source not functioning properly

I am attempting to dynamically load an image and HTML using Angular but it doesn't seem to be working. Here is what I have tried: <img ng-src="img/{{product.Category}}/{{product.id}}.jpg"> and also this: <img src="img/{{product.Category}}/ ...

The content of the modal box is determined by the custom field

I need your help with displaying different content in a modal box using featherlight.js. The idea is simple: If there is an image, it should display the image. If not, it should show a SoundCloud URL iframe. But for some reason, it's not working as e ...

Text displayed on top of tooltip

I'm currently working on implementing tooltips with dynamic content on my website. However, I am facing an issue where the content outside the tooltip is displayed over one of my tooltips. Check out the Demo here Here's the code snippet: /* ...

When ALIGN-ITEMS: CENTER is removed, the <a> element expands to fill the entire line

Currently, I am delving into the world of CSS and grappling with a particular behavior that has caught my attention. section{ display: flex; flex-direction: column; align-items: center; } .banner-area a.banner-btn{ padding: 15px 35px; backgrou ...

Customize HTML styles using Angular Material

I've noticed that my index.html file has a lot of style elements when using Angular Material, and I'm not sure why. Here's an example in the header element where different classes are used for Angular Material components. https://i.sstatic. ...

Aligning a list in the center without adding any indentation

So, I have this list that I want to center using some CSS magic. I did some searching and found a solution to remove the list style and left margin. But I really want to make sure it's perfectly centered, so I added text-align:center;. However, I not ...

conceal selected input during ajax request

One of the modules I'm using added a button to my site. However, when this button is clicked, the module automatically sends an ajax request (and unfortunately I can't modify the third party code). How can I dynamically hide and show this button ...

How to target a form in jQuery without using a class selector

Within my project, there exists a form, <form id="form3" name="form3"> <input type="text" id="number" name="number" value="" >Number</input> <button type="button" onclick="submit();">Submit</button> </form> When at ...

Attach an object securely to a specific spot

I'm facing an issue with my product cards where the text mentioning "free shipping" is not aligned properly when there are no ratings. How can I ensure that all free shipping texts are positioned consistently on the card? Should I modify the position ...

Displaying a portion of variables upon user interaction using a user interface, nearpoint/renderprint/verbatimTextOutput('print')

Here is the code I have been using for my Shiny application. I am trying to figure out how to specifically utilize the click="plot_click" / near-point / render print functionality to display certain data points. If you take a look at the image linked below ...

Adding a component dynamically with a link click in Angular: A step-by-step guide

I am encountering an issue with my web application setup. I have a navigation bar, a home page with left and right divs, and a view-associates component. My goal is to dynamically add the view-associates component into the home's right div when a spec ...

Attempting to implement an onclick event on an image object in mobile Safari on iPhone, but unfortunately encountering difficulties in the process

I am attempting to dynamically add some objects to a div and then programmatically initiate a click event on the first image once they have all been created. The code below is successful in doing this on Firefox for PC, however, when testing it on an iPhon ...

Managing iframes in React using reference methods

Trying to set the content of an iframe within a React component can be a bit tricky. There is a component that contains a handleStatementPrint function which needs to be called when the iframe finishes loading. The goal is to print the loaded iframe conten ...

The text for the Google chart is nowhere to be found

After creating a test project using the Google Chart example, I noticed that some text from the chart is missing after adding CSS. Here is the CSS code I used: html, body { font-size: 100%; height: 100%; width: 100%; } body { background: ...

Guide to using Python and Selenium to automate clicking the "Load More" button on the webpage "https://github.com/topics"

With just one click of the load more button, I can uncover a plethora of information and scrape additional HTML content beyond what is initially shown. In this scenario, the task at hand involves navigating to github.com/topics and locating the singular b ...

Is the media-heading situated at the base of the picture?

Wondering if it's possible to create a horizontal list of images with the image-heading under each image using Bootstrap 3. I couldn't find any information on this in the documentation. <h5 class="media-heading pull-left">One</h5> &l ...

Troubleshooting issue with CSS3 linear-gradient not functioning as expected

After watching a CodePen demo where CSS3 linear-gradient was used to create color effects, I attempted to use the same property on jsFiddle but it wasn't working. Can someone help me troubleshoot this issue? You can view the original CodePen code her ...