Create dynamic Bootstrap 4 menus featuring three levels of navigation - the initial dropdown sub-menu may not display any selectable options

Using Bootstrap 4 and jQuery 2.2.4, I've created a navbar with three layers of menus, comprising two levels of drop-downs from the top-most level.

Everything works smoothly except for a glitch on mobile devices. The menu collapses to the hamburger icon properly and reveals the menu/sub-menus when clicked. However, an issue arises when attempting to navigate through the sub-menu items; they retract as the mouse moves down, making it impossible to select any items below that level. On actual mobile devices where there is no mouse input, touching the sub-items does not yield any response.

This problem specifically affects the first level of sub-menu items related to "Smart Phone," while the second level items under "Computer" function correctly. This unusual behavior occurs regardless of whether the sub-menu pertains to Smart Phones or Computers.

A video has been created to illustrate this issue further (https://drive.google.com/open?id=1X_3kY-PBEgLra_mhvpZwPRsQMxd2-SRD).

I believe this issue may be an easy fix for those experienced in the matter. Any guidance on rectifying my mistakes would be greatly appreciated :)

To provide context, here's the related code...

  1. CSS
 /*=========================== Navigation ============================ */

    .navbar {
        background-color: #fff;
        box-shadow: 1px 5px 10px rgba(49, 49, 49, 0.21);
    }

    .navbar-nav a {
        font-family: 'Nunito', sans-serif;
        font-weight: 700;
        font-size: 16.5px;
        letter-spacing: 0.5px;
        line-height: 25px;
    }

    .navbar-nav a {
        color: #404044;
    }

   ...
   ...


/* navbar brand */

.nav-brand {
    line-height: 20px;
    margin-top: 0px;
}

    .nav-brand img {
        max-height: 60px;
    }

.navbar-brand i {
    vertical-align: sub;
    margin-right: 10px;
    font-size: 45px;
}

...
...

  1. HTML
<div id="navbarContent" class="collapse navbar-collapse">
    <ul class="navbar-nav mr-auto">

        <li class="nav-item dropdown">
            <a id="dropdownMenu1" href="#" data-toggle="dropdown" aria-haspopup="true" 
            aria-expanded="false" class="nav-link dropdown-toggle">Products
            </a>
            <ul aria-labelledby="dropdownMenu1" class="dropdown-menu border-0 shadow">
                <li><a class="dropdown-item" href="/phonecase">Phone Case</a></li>

                ...
                ...

            </ul>
        </li>

        ...
        ...

    </ul>
</div>

Your assistance in resolving this matter is highly appreciated!

Answer №1

After countless attempts and experimentation, I am thrilled to announce that I have finally discovered the solution! Success!

All it took was a minor modification on a single line within the CSS code:

original...

    .navbar-nav li:hover > .dropdown-menu {
        display: block;
    }

updated to...

    .navbar-nav li:hover > .dropdown-menu {
        display:grid;  /* changing "block" to "grid" fixed everything (except for compatibility with IE11, but that's a separate issue)
    }

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

Creating an artistic blend by layering p5.js drawings over images in an HTML canvas

I'm having a tough time solving this issue. My goal is to overlay circles on top of an image, ideally using HTML for the image. However, I just can't seem to make it work. let img; function setup() { createCanvas(800,800); img = loadImage(&qu ...

Is there a way to implement the adjacent selector in combination with the :before selector?

Hello there, I am working on a timeline area with a slick effect and have implemented slick.js for that purpose. I am trying to change the color of my spans within the elements. Specifically, I changed the first span in the slick-active class element succe ...

Whenever a tab is refreshed, the page will automatically redirect to the first tab

When using the application below, if the user is not in Tab 2 or Tab 3 and clicks on refresh, the page automatically goes to Tab 1. Is there a way to prevent this behavior and keep the user in their current tab after refreshing? Any suggestions on how to ...

Revamp responsiveness in bootstrap 3 for printing with @media queries

My goal is to disable the responsive features of bootstrap when the event javascript:print() is triggered. This way, I want my webpage to maintain the column grid layout that I have defined, regardless of screen size. One solution suggested in this answer ...

Switch classes according to scrolling levels

My webpage consists of multiple sections, each occupying the full height and width of the screen and containing an image. As visitors scroll through the page, the image in the current section comes into view while the image in the previous section disappe ...

What are the steps to reveal the second element once the first one has vanished?

Is there a way to delay the appearance of the second square until after the first square has disappeared? For example, I want the first square to appear after 3 seconds and then disappear, followed by the second square becoming visible after 11 seconds. ...

What are the various methods for incorporating icons and logos into website design?

Can anyone provide insights on the quality of logos and icons used in professional websites? I often create logos and icons using Illustrator, but when comparing them to icons on websites like those shown in the provided image and links, mine appear blurry ...

Customize the background color of a Material UI row with varying colors for each cell

I am facing an issue with a Material UI table in React 18 where each cell has a different background color, causing the hover style on the row to break. Despite trying various solutions, I have been unable to find a resolution. For reference, you can see ...

Transformation of CSS into SASS (or LESS)

Looking for recommendations on CSS to less or CSS to sass conversion tools. I've come across a couple like and , but unsure of their reliability. Any insights or recommendations on other tools would be highly appreciated. I have a sizable CSS code ba ...

Tips for properly showcasing images on a webpage after ensuring all other content has loaded

Is there a way to have an image load last on a webpage after all other content has been loaded? I have an image that is retrieved from a database when a button is pressed, but I would prefer for the entire page to load first and then display the image. C ...

How can I stop the CSS border of an iframe from flickering and what are some solutions to fix it?

I am encountering an issue with my iframe border when using CSS. The problem arises in Chrome where the border disappears upon resizing the page, while Safari changes the size (Firefox appears unaffected) https://i.sstatic.net/ZUi9z.gif Are there any kno ...

Create a stylish Bootstrap 3 modal featuring an image and convenient scroll bars

My dilemma is with a modal dialog containing an image of fixed width set at 1500px. I want the image to maintain this size and for scroll bars to appear on smaller screen sizes, allowing users to scroll through the entire image. Essentially, I need the mod ...

Adding extra space to the list items in CSS causes the text to become static and unaffected by fluctuations in the line-height

Here's the problem I'm facing: I have a basic list consisting of a shopping cart, login and user registration. I want to adjust the position of the list by adding padding, but every time I do so, the line height also increases. Is there a workaro ...

Optimal method for utilizing @font-face syntax

Recently, I've been utilizing this specific model @font-face { font-weight: WEIGHT; font-style: STYLE; font-family: 'NAME'; src: url('font.eot'); src: url('https://dl.dropboxusercontent.com/s/dey3lzjdpgszxzt/myriad-webfont.eo ...

Ways to increase the spacing between content boxes using Bootstrap

I currently have a row of three Bootstrap boxes structured like this: <div class="row"> <div class="col-lg-4 pathBoxMain"> <h2>Content</h2> </div> <div class="col-lg-4 pathBoxMain"> <h2>Content</h2> </di ...

Obtaining visuals in a specific manner

I have a customized slider (flexslider) with 10 images per slide. The images are currently manually inserted, but I want to optimize the slider to dynamically extract images using PHP. However, my current setup only displays one image per slide. How can I ...

Inexplicably bizarre HTML glitch

I am currently utilizing a comment system that involves adding a new row to a SQL database. The system seems to be working fine; however, when I try to display the comments, the formatting of the comment div becomes all jumbled up. You can view the page wh ...

Improving Material UI Responsiveness: A Comprehensive Guide

Could someone please help me resolve the overflow issue in my UI? You can view the overflow here. The second image explains the reason behind it, which you can see here. I am currently working on fixing my UI using React and Material UI. When checking the ...

What is the process for taking a website project running on localhost and converting it into an Android web application using HTML, CSS, and JavaScript

Looking for recommendations on how to create an Android web application using HTML, CSS, and JavaScript. Any suggestions? ...

Adding CSS code to my index.css file in React is not reflected in my application

I've been following a tutorial on YouTube about reactJS, and the YouTuber recommended importing a CSS file into index.css to properly style the website. However, when I tried copying the CSS code and importing it into both App.js and Index.js, nothing ...