Having issues with a drop-down in Bootstrap. Is there anyone who can assist in getting it to function

I recently implemented a drop-down menu on the top navigation of my website. However, after applying Bootstrap to one of my pages, the drop-down menu stopped functioning properly.

Below is the code that was applied:

    <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6b0904041f181f190a1b2b5e45584559">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dcbeb3b3a8afa8aebdac9ce9f2eff2ee">[email protected]</a>/dist/js/bootstrap.bundle.min.js"></script>

Bootstrap implementation in the body section:

  <div class="topnav" id="myTopnav">
    <div class="topnav-left">
    <a href="/"><img src="Img/Signature-Black.png"></a>
    </div>
    <a href="./contact.html">Contact</a>
    <a href="./about.html"> About</a>
    <div class="dropdown">
        <button class="dropbtn">Blog <i class="fa fa-caret-down"></i></button>
        <div class="dropdown-content">
          <a href="#">Link 1</a>
          <a href="#">Link 2</a>
        </div>
    </div>
    <a href="./photos.html">Photos</a>
    <a href="javascript:void(0);" class="icon" onclick="myFunction()">
        <i class="fa fa-bars"></i>
    </a>
  </div>

    <script>
        function myFunction() {
            var x = document.getElementById("myTopnav");
            if (x.className === "topnav") {
            x.className += " responsive";
            } else {
                x.className = "topnav";
            }
        }
    </script>

External CSS code for the navigation bar:

.topnav {
    overflow: hidden;
    background-color: transparent;
    z-index: 100;
    align-items: center;
    top: 0;
    left: 0;
    width: 100%;
    padding: 30px 10%;
}
  
.topnav a {
    float: right;
    color: black;
    text-align: center;
    padding: 10px 20px;
    text-decoration: none;
    font-size: 18px;
    font-weight: 500;
    margin-right: 35px;
    transition: 1s;
}

  /* More CSS code here */

While I am not very experienced with using Bootstrap, I am hopeful that there is a simple solution to retain the design applied to the navigation links without having to remove Bootstrap altogether. I would greatly appreciate any advice or suggestions on how to resolve this issue. Thank you!

After testing other pages, I have narrowed down the problem to the interaction between Bootstrap and the drop-down menu. Removing Bootstrap enables the drop-down menu to work correctly, however, it disrupts the layout of other elements on the page.

Answer №1

There seems to be a clash between your dropdown and the Bootstrap dropdown. "dropdown" is a class name in Bootstrap that is used in both CSS and JavaScript files.

You may want to consider using the Bootstrap dropdown and adjusting its style, or using a different class name altogether to avoid conflicts.

Answer №2

<div class="toggle-menu">
    <button class="toggle-btn">Explore <i class="fa fa-caret-down"></i></button>
    <div class="toggle-menu-content">
      <a href="#">Page 1</a>
      <a href="#">Page 2</a>
    </div>
</div>

This portion of your code is causing a conflict with the custom CSS you've defined below:

    /* Toggle Menu */
.toggle-menu {
    float: right;
    overflow: hidden;
}
  
.toggle-menu .toggle-btn {
    font-size: 18px;
    font-weight: 500; 
    border: none;
    outline: none;
    color: rgb(0, 0, 0);
    padding: 10px 20px;
    background-color: inherit;
    font-family: inherit;
    margin-right: 35px;
}

/* Toggle Menu + additional menu hover */
.topnav a:hover, .toggle-menu:hover .toggle-btn {
    color: #daa520;
    transition: 1s;
}
  
.toggle-menu-content {
    display: none;
    position: absolute;
    background-color: transparent;
    min-width: 160px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    z-index: 1;
}
  
.toggle-menu-content a {
    float: none;
    color: black;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    text-align: left;
}
  
.toggle-menu-content a:hover {
    color: #daa520;
}
  
.toggle-menu:hover .toggle-menu-content {
    display: block;
}

It is not recommended to use custom CSS properties that conflict with Bootstrap selectors. Consider exploring Bootstrap's pre-built dropdowns for easier implementation and customization.

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 am unable to view the input appearing inside the input box on my React/HTML application

I have been developing a React app for building portfolios, but I am facing an issue where I cannot see any text that I type into my input boxes. Can someone please help me troubleshoot this issue? Any assistance would be greatly appreciated. I have made ...

What is the method for customizing the background color in a .vue file using Bootstrap?

Can anyone assist me in updating the background color of a div class from grey to white? The code is within a .vue file using Bootstrap and includes an enclosed SVG file. Here's the snippet: <div class="text-left my-3 bg-white"> <button var ...

Dynamic sidebar that adheres to the content and is placed alongside it using JavaScript

I am in need of creating a sticky sidebar that will float beside my content column. The purpose of this sidebar is to contain jump links on the page, similar to what can be seen on this page, but with the navigation buttons positioned directly next to the ...

Creating a visually appealing lineup of images with CSS3 and optimal methods

Hey there, I'm diving into the world of HTML5 and CSS3 and feeling a bit lost. Can't seem to find the right solution for what should be a simple task. My goal is to create a line of clickable images/links on my website similar to how Stack Overfl ...

The debate between using backticks and colons in TypeORM queries

Lately, I've been crafting queries utilizing backticks const firstUser = await connection .getRepository(User) .createQueryBuilder("user") .where(`user.id = '${id}'`) .getOne(); However, in the typeorm documentatio ...

Is there a way to create a popover menu in VueJS without using JQuery

I found exactly what I need in this helpful answer. It demonstrates a menu appearing when clicking on a table row. The dilemma is that it relies on JQuery... Therefore, I am curious if achieving the same functionality without JQuery is possible. Maybe thr ...

AngularJS: updating a module

I recently started learning AngularJS and I need some guidance on how to refresh the data in a table within a module (specifically, a list of names and post codes). Below is the script where I am trying to reload the JSON file upon clicking a button: < ...

What is the best way to iterate over a multidimensional array in Angular/Ionic?

I've been struggling to find a solution tailored for looping in a .ts file instead of HTML. My main objective is to iterate over an array and compare the entered value with the keys. If there's a match, I want to retrieve the values stored withi ...

Tooltips for Images in Vega Charts

As a developer skilled in d3, I am navigating the world of VEGA charts and seeking guidance on how to incorporate an image in a tooltip. Do you have any suggestions for me? For example, considering this particular scenario: If we assume there is an addit ...

Executing JavaScript code within ASP.NET Visual Basic

My current web application uses jQuery and JavaScript, but I want to add more features that are supported in ASP.net VB. However, I am unsure if the JavaScript can run after the VB code. Essentially, I would like the web app to follow this sequence: ...

Angular 8 carousel featuring a dynamic bootstrap 4 design with multiple images and cards displayed on a single slide

I am currently working on a dynamic carousel that should display multiple cards or images in one row. Initially, I faced an issue with the next and previous buttons not functioning properly when trying to display multiple cards in one row. After some onlin ...

The jQuery load() method may not load all elements

I've been struggling with a query issue for quite some time now. I have a Content Management System that I want to integrate into my website, but unfortunately, I am unable to use PHP includes. As an alternative, I decided to utilize jQuery instead. D ...

conceal the HTML code from the students

As an instructor of an HTML/CSS course, I often assign tasks that require students to replicate the design of a webpage. However, providing them with direct links to the page makes it easy for them to decipher my methods and simply copy the work. Furthermo ...

Failure to execute the success function

My current issue involves making an AJAX call to retrieve a record from the database. Despite console logs showing that the record is successfully returned, the success function fails to execute. function ajaxForParent() { var search = document.getEle ...

Restricting the type of user input in HTML forms

Requirements: Input must be a whole number between 2 and 99, inclusive. Current Solution: <input required type="number" min="2" max="99" oninput="this.value = Math.abs(this.value)" maxLength="2" matInp ...

Unforeseen outcomes arise when toggling expansion in JavaScript

I have a pop-out div at the top of my page that expands and closes on toggle. Also, when I toggle the pop-out div, it changes the top position of another div (a side pop-out menu). The issue is that the side pop-out menu should only appear when clicking ...

Having trouble passing arguments to button methods in jasmine when applying vue and moment libraries

I am working on unit testing a Vue app using `jasmine` and `karma`. Here is an example of the code inside one of my components: After fetching data from a database with `v-for=(data,index)`, I am displaying the `data.date` in the template: <p class=&qu ...

Adjacent components

I have a query regarding the utilization of Angular. I aim to align the sentences side by side. These are two distinct components that I developed. I wish for recipe-list and recipes-details to function properly, with both statements displayed alongside ...

Assistance needed with sending JSON data to a PHP server using the POST method

I am attempting to transfer JSON data from an HTML form to a PHP server using the POST method. The issue I am encountering is that my code always ends up in the fail block within the callback function. Despite this, the Firebug console (ctrl+shift+J) does ...

Differences Between Data Captured from Form Submissions and Data Obtained Through Ajax

When attempting to incorporate reCAPTCHA into my MVC site, I encountered an issue where it would not validate unless submitted from a form. Here is the current implementation: @using(Html.BeginForm("VerifyCaptcha", "Signup") ) { @ReCaptch ...