Creating a responsive dropdown submenu with Bootstrap 4, utilizing HTML, CSS, and jQuery

My HTML code includes CSS, jQuery Bootstrap 4 elements. I am attempting to add a dropdown submenu to my main menu when hovering over it. However, I am facing issues in getting the dropdown submenu to work properly. When I hover over main menu items like Course, TextBook, and Car, I want the submenu to appear below the main menu. Interestingly, the dropdown submenu works fine when I remove bootstrap.min.css, announcement-container div, and custom-menu-container div. But I need to include Bootstrap and the other menu elements as well. If they are present, the dropdown submenu doesn't work as expected. Can you provide any guidance on how to resolve this issue? I am using Bootstrap 4. The desired outcome for the main menu and submenu should resemble the image in this link: https://i.sstatic.net/2L4Qo.png

Below you can find the code snippet:

:root {
  --background-color: #FFF;
  --button-bg: #FFF;
  --secondary-bg-color: #F6F5FA;
  --fontfamily: 'Ibarra Real Nova', serif;
  --cormorant: 'Cormorant Garamond', serif;
}

* {
  border: none !important;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: var(--background-color);
  padding: 0;
  margin: 0;
}

...
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh"
crossorigin="anonymous">
<link rel="stylesheet" href="Lib/fontawesome-5/css/all.css">
<link rel="stylesheet" type="text/css" href="HTest.css">
</head>

<body>
  <header>
    <div class="container-fluid wrapper p-0">
      <div class="row announcement-container">
        <div class="col-md-12"><h5>Some text here</h5></div>
      </div>
      <div class="row nav-container">
       ...
      </div>
  </div>
</body>
</html>

The desired appearance of the submenu should be similar to the provided image.

Answer №1

To achieve the desired UI, you can utilize the bootstrap navbar and make adjustments to the dropdown class.

.nav-item {
  display: inline-block;
}

.nav-item a {
  color: #FFF !important;
}

.nav-item:hover {
  background: red !important;
}

.nav-item:hover .dropdown-menu,
.nav-item.active .dropdown-menu {
  display: flex;
}

.nav-item .dropdown-menu {
  background: red;
  padding: 0;
  width: 100%;
  margin: 0;
  border-radius: 0;
  border: none;
}

.nav-item .dropdown-item {
  display: inline-block;
  background: red;
  width: auto;
  padding: .5rem 1rem;
}

.dropdown-item:focus,
.dropdown-item:hover {
  background: rgba(0, 0, 0, 0.2) !important;
}
<!DOCTYPE html>
<html>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<link rel="stylesheet" href="Lib/fontawesome-5/css/all.css">

<ul class="navbar navbar-dark bg-dark p-0 justify-content-start">
  <li class="nav-item">
    <a class="nav-link">
          Home
        </a>
  </li>
  <li class="nav-item">
    <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
          About
        </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>
</ul>

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

Modify the appearance of a specific <td> element using JavaScript to change its color

I am working on creating a quiz using HTML, displayed in a table format. Upon verification, I want to highlight the correct choice (which is represented by a <td> tag) in green, and the incorrect choice in red using the background property. Is there ...

Attempting to modify the environmental variable within node.js via the terminal proves to be a fruitless endeavor as the value consistently remains undefined

Recently, I entered the world of backend development and came across this JS code utilizing express: const express = require('express'); const app = express(); const port = process.env.PORT || '3000'; app.listen(port, ()=> console.lo ...

` `issues with fmt:massage tag` `

When I try to update my page elements using ajax, I encountered a problem: the fmt:message tag doesn't work when I set it in javascript. In the JSP page everything works fine: <div id="div"> <fmt:message key="search_select_country"/> & ...

What is the process for obtaining the Tag from a React Component?

Not the HTML DOM element tag, the JSX tag, the react class name. As I work on creating an editor, adding items to the canvas array requires me to check and call the appropriate method based on what is being added. A simplified version of my idea: changeS ...

Using Jquery to alter elements during every iteration loop

With the help of jquery, my goal is to iterate through all elements that belong to the "item" class and give them different background colors based on their index position. The array mapcolor contains a variety of colors (with a length matching the number ...

Understanding how to parse a JSON object in JavaScript is a

In my JSON object, I have the following data: rows = [{name:"testname1" , age:"25"}, {name:"testname2" , age:"26"}] My goal is to extract the names and store them in a variable like this: name = "testname1, testname2"; ...

Incorporating traditional Bootstrap styling directly into a React application without relying on the react-bootstrap library

My goal is to incorporate my existing bootstrap components into a React project without having to rewrite them to work with the react-bootstrap library. While I have successfully integrated the bootstrap CSS, I am facing issues with the functionality aspec ...

Struggling with loading external scripts within background.js in Chrome extensions?

I am facing an issue with my chrome extension. I am unable to call an external script, specifically the ethereum script (web3.min.js), from within my background.js file. The error message I receive is: Uncaught EvalError: Refused to evaluate a string ...

Formatting issue with selecting checkboxes in Primefaces DataTable filter menu

I decided to replicate the Primeface showcase for filters on my Local JBoss installation by referring to the link provided below: http://www.primefaces.org/showcase/ui/data/datatable/filter.xhtml. However, I encountered an issue where my selectCheckboxMenu ...

Angular 4: The Authguard (canActivate) is failing to effectively block the URL, causing the app to break and preventing access to all resources. Surprisingly, no errors are being

I have created an authguard, but it seems to not be blocking the route when the user is logged out. The authentication workflow in the app works fine, as I am using traditional sessions on the backend database. I have also verified the state of the auth se ...

Exclusively utilize optgroup multiple functionality within bootstrap-select

I'm currently utilizing https://github.com/snapappointments/bootstrap-select/ version 1.13.18 and I am in need of a solution where only optgroup options can have multiple selections. This means that if a non-optgroup option is selected, all other opti ...

Glowing effects on svg shapes

I'm looking to add a pulsing light animation around an SVG half circle shape that I have created. After experimenting with CSS and Webkit, the closest I've come is achieving a pulsing light around the parent element, rather than the actual shape ...

Setting the default date in angular-bootstrap-datetimepicker: a step-by-step guide

I am currently utilizing the angular-bootstrap-datetimepicker module for allowing users to choose a date and time. How can I set a default date and time when the view initially renders? Is there an attribute available that allows us to assign a boolean val ...

AngularJS: intercepting custom 404 errors - handling responses containing URLs

Within my application, I have implemented an interceptor to handle any HTTP response errors. Here is a snippet of how it looks: var response = function(response) { if(response.config.url.indexOf('?page=') > -1) { skipException = true; ...

Tips for fetching individual item information from Firebase real-time database using Angular 9 and displaying it in an HTML format

product.component.ts import { AngularFireDatabase } from '@angular/fire/database'; import { ProductService } from './../product.service'; import { ActivatedRoute } from '@angular/router'; import { Component, OnInit} from &apo ...

Ensure that both textarea and pre elements have equal dimensions and line wrapping behavior in Internet Explorer

I am in the process of implementing a dynamic textarea that resizes automatically, based on a technique discussed in this article: Alistapart: Expanding Textareas (2011). The idea is quite straightforward: by using a pre element to mirror the input in the ...

Guide on populating a table with user input using jQuery and ajax

For the past few days, I've been attempting to populate a table using jQuery and ajax based on search results, but unfortunately, it's not working out for me. Below is the HTML code snippet: <form class="form"> <div class="form-gro ...

Execute the JS function during the first instance of window scrolling

Currently, I have implemented a typewriter effect on my website that triggers when the user scrolls to a specific section. However, I want this effect to occur only once. Unfortunately, every time the user scrolls again (in any direction), the function is ...

What's the best way to manage the onClick event for individual input submit types using jQuery?

As a novice in jQuery, I am still in the learning phase. However, I urgently require a solution to set up a click event registration for each button within my table. The table below is created using GridView: <div id="gridView"> &l ...

Customize time formatting in Angular to accommodate localized time formats

I am utilizing Angular's localization service version 8.3.28 to support English, Spanish (Mexico) with code es-MX, and Spanish (Spain) with code es-SP While using the date pipe: {{ foo.Date | date: 'shortDate' }} The dates are changing to ...