Issues with toggling the Bootstrap 4 Navbar in ASP.NET

I have built a website using Bootstrap 4 in ASP.NET (.NET Framework). However, I am facing an issue when switching the website view from PC to mobile. The navbar-toggler-icon button is not working properly as the navbar content does not show up when I press the toggler-icon button. Even though the navbar-collapse id matches with the data-target, it still does not work. Can anyone assist me with this? Here is the code snippet:

<nav id="navbar" class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
    <div class="container">
        <a class="navbar-brand" href="/index.aspx">
            <img class="logo" src="img/Logo/logo_Rueston.png" alt="">
        </a>
        <button class="navbar-toggler" type="button" data-toggle="navbar-collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarCollapse">
            <ul class="navbar-nav navbar-center ml-auto">
                <li class="nav-item ml-3">
                    <a class="nav-link" href="/index.aspx">Home<span class="sr-only">(current)</span></a>
                </li>
                <li class="nav-item ml-3">
                    <a class="nav-link" href="#">About</a>
                </li>
                <li class="nav-item ml-3">
                    <a class="nav-link" href="#">Products</a>
                </li>
                <li class="nav-item ml-3">
                    <a class="nav-link" href="#">Rueston Water</a>
                </li>
            </ul>
            <ul class="navbar-nav ml-auto">

                <li class="nav-item ml-3">
                    <a class="nav-link" href="#">
                        <asp:Label ID="lbLogin" runat="server" Text="Login"></asp:Label>

                    </a>
                </li>
                <li class="nav-item ml-3">
                    <a class="nav-link" href="#">
                        <asp:Label ID="lbSignup" runat="server" Text="SignUp"></asp:Label>

                    </a>
                </li>
            </ul>
        </div>
    </div>
</nav>

Here is a screenshot of the issue:

Before clicking the toggler button - Image Link

After clicking the toggler button - Image Link

Answer №1

Update the data-toggle="navbar-collapse" attribute in the button to data-toggle="collapse"

<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
</button>

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

Unable to view Bootstrap Icons in Gulp 4

I recently integrated the new bootstrap icons npm package into my project using Gulp 4, the latest version. Everything was installed successfully and was working smoothly. However, I encountered an issue when trying to declare the icon in my index.html fi ...

Utilizing Image Sprites to Enhance Your Website's

Would it be more advantageous to utilize image sprites in CSS, or opt for numerous individual image files instead? Is there a clear preference between using multiple images over one sprite, or vice versa? ...

The issue arises when trying to pass the name of an image to a Vue component, but

My goal is to dynamically create an input component with a specific icon for each input. The icon is set as a background image in the CSS, and it works when directly included like this: background-image: url(../../assets/icons/email.svg); However, when I ...

Tips for sending a Python email with attachment and including an HTML body along with an alternative plain text body

Using Python, I have developed code to send emails with HTML bodies and attachments. Additionally, I would like to include a plain text email body for clients that cannot display HTML content properly. While my code works in most cases, I've encounter ...

Unable to add dynamically created content after deleting all associated elements

In my code, I have a Select element that generates dynamic HTML below it based on the selected value. Before appending the HTML after the year id, I try to remove all elements with the class quarter, but it seems like it's not working properly. $( ...

What further steps are necessary beyond simply linking the Bootstrap css and js files in order to fully utilize Bootstrap classes?

While generating dynamic HTML, I've referenced bootstrap CSS and JS along with jQuery to apply a bootstrap class to an h1 element. However, the appearance of the h1 text remains unchanged. The key part of the HTML is being generated by the following c ...

The Art of Unraveling a String in SQL Server

Could someone please advise on the most effective method to convert special characters in a string back to their normal form using HTML decoding? ...

Ways to retrieve nested #document within html?

Hey there! I'm trying to figure out how to use document.querySelector() to locate span id='t1', but I'm unsure of how to access the #document element and its contents. Is it possible to select elements within #document? Currently, I ha ...

Having difficulty showcasing the JSON data within the dropdown list within an HTML table

In my HTML table, I have 4 rows with Order ID and Product Comments columns disabled. Users can enter data in other columns and submit it. Upon submission, I receive a JSON object which I iterate through and display in the table. I am facing two challenges ...

JavaScript resets the timer whenever the page is refreshed

Is there a way to maintain the timer in a quiz even after refreshing the page? <html><h1>Js Timer</h1> <div style="font-weight: bold;" id="quiz-time-left"></div> <script type="text/javascript"> var total_seconds = ...

Exploring the World of SignalR- Hubs, Injecting Dependencies, and Managing Controllers

I've been extensively researching SignalR through various sources but I'm encountering a roadblock. My goal in a chat application is to persist messages outside of the Hub so that when a user joins the chat, they can view all previous messages s ...

Pattern matching for replacing <a> tags

As a beginner in the world of regular expressions, I am eager to learn more about it. Currently, my goal is to extract only the inner text from an HTML tag and remove the surrounding tags. For example: Original: Lorem ipsum <a href="http://www.google.e ...

Struggling with Extracting HTML Attribute

I am a beginner in python and facing challenges with scraping HTML code. My objective is to extract the text "Coupon", "Maturity Date", and "Initial Offering Price" along with the text within the float-right class from the provided HTML snippet. This exce ...

Is there a way for me to convert my HTML code into a Vue component?

I am trying to display a tiff file on a web page, I successfully did it with test.html, but now I need to do it within a vue file. How can I achieve this? Additionally, I am unsure about the specific content in the tiff.js[![enter image description here][1 ...

Choosing multiple images by clicking on their alternative text with jQuery

I am currently working on a project that involves clicking on a thumbnail to enlarge the image and display its name (alt) below it. I have made progress, but there seems to be an issue where only one image is displayed no matter which thumbnail I click on. ...

Error: Unable to locate module '@material/core/Grid'

After cloning a repository that is built with MUI, I noticed that certain components were already imported and working seamlessly. These components include: import Card from '@mui/material/Card' import CardActions from '@mui/material/CardAct ...

Set the element's text color to match the placeholder color specific to each browser

Can CSS be used to dynamically set the font color of a custom element to match the default input placeholder color of the current browser/OS? Thank you. ...

Adjusting the inner div dimensions to be 100% of the body's size without relying on the parent div using JavaScript

I have a main layer with multiple layers stacked on top of it. I need the second layer to extend its width to match the body's width. Main Project: http://example.com What I've tried: I looked into: Solution for matching div width with body ...

The Div overlay vanishes once the Javascript function is finished running

Initially, take a look at this fiddle: http://jsfiddle.net/ribbs2521/Q7C3m/1/ My attempt to run JS on the fiddle has been unsuccessful, but all my code is present there, so we should be fine. I was creating my own custom image viewer, and everything was ...

Rewrite URL in classic ASP from HTML website to another HTML page

I am currently working on a website project that requires URL rewriting. I have a page located at www.mywebsite/Index.html. When a user enters this URL into their browser and hits enter, I want the content of the page to load from www.mywebsite/Index.asp b ...