The Bootstrap 5 mega menu vanishes in the blink of an eye

Having some trouble with my Bootstrap 5 mega dropdown. It seems to disappear too quickly when I try to select the contents. I suspect there may be some CSS causing this issue, but I can't seem to pinpoint it.

I've already attempted to adjust the transition time and z-index value without success. Any suggestions on which CSS property needs to be added to maintain the hover effect?

.header {
  min-height: 70pt;
}

#alaid-header .logo h1 {
  font-size: 38px;
  margin: 0;
  line-height: 0;
  font-weight: 600;
  letter-spacing: 1px;
}

#alaid-header .logo h1 a,
#alaid-header .logo h1 a:hover {
  color: #3c4133;
  text-decoration: none;
}
/* more styles omitted for brevity */
.nav-item {
  padding: 0.5rem 0xp;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.0.2/css/bootstrap.min.css"/>

<header id="alaid-header" class="d-flex align-items-center bg-white shadow header">
  <div class="container d-flex justify-content-between">
    <div class="logo">
      <h1 class="text-light">
        <a href="index.php">
          <img src="https://via.placeholder.com/50" class="w-100" />
        </a>
      </h1>
    </div>

    <nav id="navbar" class="navbar alaid-navbar">
      <ul>
        <li><a class="nav-link active" href="index.php">Home</a></li>
        <li class="nav-item  dropdown-hover position-static">
            <!-- Dropdown menu structure -->
        </li>
      </ul>

      <i class="bi bi-list mobile-nav-toggle"></i>
    </nav>
  </div>
</header>

<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.3/js/bootstrap.min.js"></script>

Answer №1

To ensure smooth navigation, it's important to have the hovered element positioned next to the dropdown menu. This way, transitioning from one to the other will not cause any interruptions.

Here are some code snippets for achieving this:

.header {
  min-height: 70pt;
}

#alaid-header .logo h1 {
  font-size: 38px;
  margin: 0;
  line-height: 0;
  font-weight: 600;
  letter-spacing: 1px;
}

#alaid-header .logo h1 a,
#alaid-header .logo h1 a:hover {
  color: #3c4133;
  text-decoration: none;
}

#alaid-header .logo img {
  padding: 5px;
  margin: 0;
  max-height: 78px;
}

.navbar {
  padding: 0;
}

.navbar ul {
  margin: 0;
  padding: 0;
  display: flex;
  list-style: none;
  align-items: stretch;
}

.navbar li {
  position: relative;
}

.navbar a {
  color: #026a3f !important;
}

.navbar a,
.navbar a:focus {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0 10px 30px;
  font-family: "Roboto", sans-serif;
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  white-space: nowrap;
  transition: 0.3s;
  height: 100%;
}

.navbar a i,
.navbar a:focus i {
  font-size: 12px;
  line-height: 0;
  margin-left: 5px;
}

.navbar a:hover,
.navbar .active,
.navbar .active:focus,
.navbar li:hover>a {
  color: #c57b0d !important;
}

.navbar a i {
  color: #c57b0d !important;
}


/* Dropdown Styles */

.dropdown-menu {
  width: 980px;
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translate(-50%);
  opacity: 0;
  visibility: hidden;
  padding: 20px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
  transition: all 5s ease;
}

.dropdown-hover:hover>.dropdown-menu {
  display: block;
  opacity: 1;
  visibility: visible;
  z-index: 250;
}

.dropdown-hover>.dropdown-toggle:active {
  pointer-events: none;
}

.dropdown .dropdown-menu a {
  font-size: 13px !important;
  margin-left: -29px;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.0.2/css/bootstrap.min.css"/>

<header id="alaid-header" class="d-flex align-items-stretch bg-white shadow header">
  <div class="container d-flex justify-content-between align-items-center">
    <div class="logo">
      <h1 class="text-light">
        <a href="index.php">
          <img src="https://via.placeholder.com/50" class="w-100" />
        </a>
      </h1>
    </div>

    <nav id="navbar" class="navbar alaid-navbar align-items-stretch p-0 h-100">
      <ul>
        <li><a class="nav-link active" href="index.php">Home</a></li>
        <li class="nav-item  dropdown-hover position-static">
          <a data-mdb-dropdown-init class="nav-link" href="#" id="navbarDropdown" role="button" data-mdb-toggle="dropdown" aria-expanded="false">
          Lorem ipsum<i class="bi bi-chevron-down"></i>
        </a>
          
          <div class="dropdown-menu w-100 mt-0" aria-labelledby="navbarDropdown" style="border-top-left-radius: 0;border-top-right-radius: 0;">
            <div class="container mx-0">
              <div class="row my-4">
                <div class="col-md-6 col-lg-6 mb-3 mb-lg-0">
                  <div class="list-group list-group-flush">
                    <h6><strong>Lorem3</strong></h6>
                    <hr />
                    <a href="">lorem ipsum eer</a>
                    <a href="">lorem ipsum</a>
                    <a href="">lorem emsm</a>
                  </div>
                </div>

                <div class="col-md-6 col-lg-6 mb-3 mb-lg-0">
                  <div class="list-group list-group-flush">
                    <h6><strong>Dogs</strong></h6>
                    <hr />
                    <a href="">Caucaian</a>
                    <a href="">Bull</a>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </li>
      </ul>

      <i class="bi bi-list mobile-nav-toggle"></i>
    </nav>
  </div>
</header>

<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.3/js/bootstrap.min.js"></script>

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

Bootstrap 5's Vertical Ruler

Is it possible to add a vertical line that extends down the right side of the listed items on this website? I want to place the main content next to this vertical line. .first a.nav-link { background-color: #ebe0dd; } a.nav-link { font-size: 23px; ...

Manipulating JSON data fetched through AJAX beyond the success callback

I'm facing an issue with storing JSON data received via AJAX in an external variable for future use. I came across this answer on Stack Overflow (load json into variable), which provided some basic insights, but it seems like I might be missing someth ...

How can we incorporate interactive icons into the navigation bars on our Weebly site?

Recently, while using Weebly to design a website, I stumbled upon a webpage () that explains how to add icons to the navigation bar. Below is the code provided: /* External Fonts */ @font-face { font-family: 'dashicons'; src: url('fonts/ ...

Submitting with enter key on typeahead suggestions

Seeking guidance on Bootstrap typeahead: how can I configure it to submit the entered text upon pressing the enter key? Specifically, if I type "hello" in the typeahead input and hit enter, how can I submit "hello"? I've successfully disabled the aut ...

The value of an AngularJS model object cannot be altered with a dynamic key

app.controller('indexController', ['$scope', '$location', 'authService', function ($scope, $location, authService) { var vm = this; vm.$onInit = function () { vm.active = { "home": true, ...

Experimenting with d3 using Node.js, JSDOM, and Jasmine

I am new to Javascript and node.js, and I want to test if a basic bar chart is being rendered in my node.js/d3 application using jasmine. Could someone provide guidance on what steps I need to take? test.js (file that needs testing): var d3 = require(&ap ...

Separating buttons (two buttons switching on and off simultaneously) and displaying the corresponding button based on the data

My current project involves creating a registration page for specific courses. While I am able to display the information correctly, I am facing an issue with the ng-repeat function. The problem lies in all the Register buttons toggling incorrectly. Additi ...

PHP, AJAX and MySQL - dynamically refreshing a web page with multiple dropdown menus

I have a current setup that allows me to select a minimum price for display, and the page updates accordingly without any issues. However, I also want to set a maximum price for display from a different <select> (and in the future, other options such ...

Could Flexbox CSS be used to create a responsive layout like this?

Appreciate your help in advance. I am facing a challenge with the current layout. <article> <section class="content">1</section> <aside class="ads">2</aside> <section class="comments">3</section> < ...

What methods can be used to send JSON data in the body of an express router.get request?

I am currently working on setting up an express endpoint to fetch data from an API and return the JSON response in the body. We are receiving JSON data from a rest API as an array and my goal is to utilize express router.get to present this formatted JSON ...

Utilize the $sample operator following the $group stage in MongoDB queries

Consider the dataset provided below: {company:"One", employee:"John"}, {company:"One", employee:"Mike"}, {company:"One", employee:"Donald"}, {company:"One", employee:"Mickey"}, {company:"Two", employee:"Johnny"}, {company:"Two", employee:"Da ...

Internet Explorer's support for the `<summary>` tag in HTML

Is there a method to enable the summary tag in Internet Explorer 11, such as using an external library? <details> <summary>Here is the summary.</summary> <p>Lorem ipsum dolor sit amet</p> </details> App ...

Expand the dimensions of the shinydashboard dashboard page

Currently, I am using shinydashboard and have formatted my ui code in the following way: ui = dashboardPage(skin="black", dashboardHeader(disable = T), dashboardSidebar(width=300), dashboardBody() ...

The Fixed Navbar is causing sections to be slightly off from their intended positions

Utilizing a bootstrap navigation menu on my website with a fixed position. When clicking a menu item, it takes me to the designated section but slightly above the desired position. How can I ensure that it goes to the exact position upon clicking the men ...

JWPlayer encounters an issue: "undefined" function is not defined

Can anyone lend a hand with this issue I'm facing? I'm attempting to upload a video using jwplayer but encountering errors. Here is the snippet of code I'm utilizing: <script type="text/javascript"> jwplayer("leg ...

Arranging an array in Javascript containing both strings and numbers

I am working with an array in Javascript that contains elements with information about free space on different datastores: myArray = ["Datastore one - free space 34.23GB", "Datastore two - free space 56.23GB",...] I want to sort this array based on the a ...

Error: the specified item is not a valid function

As a newcomer to the world of JavaScript, I am eager to learn and explore new concepts. Currently, my focus is on centralizing the code for accessing my MySQL database within my Express JS server using promises. Below is an attempt I have made in achieving ...

Attempting to iterate through a Query each loop for the Raphael object

I'm currently facing a challenge with creating a jQuery .each() function to iterate through an array that I've constructed from a Raphael object. While I am able to achieve this using a traditional JavaScript for-loop: for (var i = 0; i < reg ...

Is it possible to modify variables in the controller when the route is changed?

My application utilizes a template and several views that are dynamically rendered based on their route: popApp.controller('HomeCtrl', ['$scope', '$routeParams', '$http', function($scope, $routeParams, $http) { ...

Tips for fixing the issue of "module ./response not found" in Node.js Express

Whenever I execute the command $ npm start this error message appears > <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8feefcfce6e8e1e2eae1fbbccfbea1bfa1bf">[email protected]</a> start > nodemon server.js ...