Utilizing multiple dropdown buttons in navigation menu items with Bootstrap 4

Trying to find a solution for having sub menus within the menu items. There are 2 dropdown buttons (Reports and Views) within a menu item that is itself a dropdown item. Clicking on the first button displays the submenu below, but clicking on the second dropdown button still displays the first submenu items instead of the second ones. Attempted to group each button using btn-group, but this breaks the buttons and causes the menu to disappear when clicked. Any advice would be appreciated. Thank you.


        <nav class="navbar navbar-expand-md Nav-colors">
        <a class="navbar-brand" href="<?php echo site_url(); ?>">
            <img src="<?php echo assetUrl('images'); ?>ups_logo.png" alt="Brand Logo">
        </a>
        <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarContent" aria-controls="navbarContent" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-text Nav-colors">Menu</span>
        </button>
        <div class="collapse navbar-collapse" id="navbarContent">
            <ul class="navbar-nav mr-auto">
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="#" id="labourPlanningDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                        Labour Planning
                    </a>
                    <div class="dropdown-menu" aria-labelledby="labourPlanningDropdown">
                        <button class="dropdown-item btn dropdown-toggle Btn-ups" type="button" id="reportsDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                            Reports
                        </button>
                        <div class="dropdown-menu Nav-submenu-colors" aria-labelledby="reportsDropdown">
                            <a class="dropdown-item" href="#">Supervisor Daily Snapshot</a>
                            <a class="dropdown-item" href="#">Manager Daily Snapshot</a>
                            <a class="dropdown-item" href="#">Employee Productivity</a>
                            <a class="dropdown-item" href="#">Metric Export</a>
                            <a class="dropdown-item" href="#">Facility Hours/FTE</a>
                            <a class="dropdown-item" href="#">Trend Graphs</a>
                            <a class="dropdown-item" href="#">Monthly YoY Graphs</a>
                        </div>
                        <a class="dropdown-item" href="<?php echo site_url('facilityperformance'); ?>">Facility Performance</a>
                        <a class="dropdown-item" href="<?php echo site_url('weeklyexcesshours'); ?>">Weekly Excess Hours</a>
                        <a class="dropdown-item" href="<?php echo site_url('targetmar'); ?>">Target MAR</a>
                        <a class="dropdown-item" href="<?php echo site_url('unitofmeasure'); ?>">Unit of Measure</a>
                        <a class="dropdown-item" href="<?php echo site_url('monthlyplanforecast'); ?>">Monthly Plan/Forecast</a>
                        <button class="dropdown-item btn dropdown-toggle Btn-ups" type="button" id="viewsDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                            Views
                        </button>
                        <div class="dropdown-menu Nav-submenu-colors" aria-labelledby="viewsDropdown">
                            <a class="dropdown-item" href="#">3 Week View</a>
                            <a class="dropdown-item" href="#">1 Month View</a>
                        </div>
                        <a class="dropdown-item" href="<?php echo site_url('manualmetricinput'); ?>">Manual Metric Input</a>
                        <a class="dropdown-item" href="<?php echo site_url('clientimport'); ?>">Client Import</a>
                        <div class="dropdown-divider"></div>
                        <a class="dropdown-item" href="<?php echo site_url('employeemapping'); ?>">Employee Mapping</a>
                        <a class="dropdown-item" href="<?php echo site_url('activityowners'); ?>">Activity Owners</a>
                        <a class="dropdown-item" href="<?php echo site_url('planimport'); ?>">Plan Import</a>
                    </div>
                </li>
                <li class="nav-item">
                    <a class="nav-link disabled" href="#">Forecast</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link disabled" href="#">Supervisor</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link disabled" href="#">Admin</a>
                </li>
            </ul>
        </div>
        <span class="navbar-text text-right">Logged in: <?php echo $ADID; ?></span>
    </nav>

Answer №1

I couldn't help but notice that some of your items have a data-toggle="dropdown", yet lack a data-target. Adding the data-target attribute would ensure that the correct items are toggled.

Take for instance, your menu button:

<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarContent" aria-controls="navbarContent" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-text Nav-colors">Menu</span>
</button>

Here, the data-target opens up the correct menu. However, your submenu toggles do not have this attribute.

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

Guide on making a prev/next | first/last button functional in list.js pagination

Is there a way to enhance my paginated index by adding prev/next, first/last buttons? I am curious if anyone has implemented these features using List.js. <script src='//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js&ap ...

Ways to modify the appearance of the Sign up page on Moodle

I'm a newcomer to the world of Moodle, currently using version 2.9. I've created a unique design for my Signup page using HTML5 and CSS. How do I go about integrating this custom page? While I understand how to change the default Login page by m ...

Looking to deactivate a particular checkbox in a chosen mode while expanding the tree branches

I encountered an issue with a checkbox tree view where I needed to disable the first two checkboxes in selected mode. While I was able to achieve this using the checked and readonly properties, I found that I could still uncheck the checkboxes, which is no ...

How to attach an event listener to an input element using Angular

I am looking to add a listener to an input element that will be triggered every time the user changes the input values. The goal is to display the current values chosen by the user. Example HTML template: <div id="idDoseLabel1" class="da ...

Rapid HTML coding dilemma

Currently, I am in the process of quickly marking up my webpage. One issue I am facing is that I would like my title to be displayed below my <nav> tag instead of beside it. Can anyone provide guidance on how to achieve this? Here is the current HT ...

Slide-out left menu using HTML and CSS

Currently, I am in the process of constructing a website that requires a menu to gracefully slide from the left side of the screen (with a width of 0px) to the right side (expanding to a width of 250px), all with the help of jQuery animations. Here is wha ...

Is there a way to configure flexbox so that its children wrap in a manner where several children are arranged alongside one specific child

My layout resembles a table using flexbox: +--------------+---------------+-----------------+---------------+ | 1 | 2 | 3 | 4 | | | | | | +---------- ...

Conceal a component when the succeeding one appears on a separate line

I'm looking for a solution to display an address on a webpage in two different formats based on the length. The first format should be: Street Number, PostalCode City If the address is too long to fit on one line, it should be displayed as: Street ...

Utilizing a JavaScript function to toggle the Bootstrap dropdown without the need for manual clicking

I've configured a Bootstrap dropdown in my site's mini cart that includes a lightbox effect to grey out the background content when the dropdown is activated. Here's the code snippet: $(".dropdown").on('show.bs.dropdown hide.bs.dropdow ...

add the closing </div> tag using jquery only

Having a slight issue here, it seems that jQuery is being overly clever. Within my HTML code, I am attempting to insert this string into a div container: </div><div class="something"> You'll notice that the closing tag comes first, foll ...

Learn how to design a customized loading screen using CSS with Phonegap

Currently working in Android with Phonegap / Cordova, I am faced with the challenge of optimizing page loading time due to numerous DOM objects being created. To address this issue, I am attempting to implement a "Loading..." screen to prevent users from b ...

What are some ways to add border styles to the Material UI TableRow Component?

In my project, I am utilizing the Table component from Material UI. I have been trying to apply border styles to the TableRow Component using scss classNames for styling purposes. Usually, the border styling is applied in the TableCell, but this doesn&apos ...

Footer not adhering to the bottom of specific pages

I have been using the code snippet below to ensure that most of my pages stick to the bottom. However, I've noticed that the ones that don't are sub-menu items that contain a contact form with captcha. I'm not sure what's causing this i ...

Tips for incorporating a CSS class representing an image into a CodeIgniter form submission

<?php $data = array( 'class' => "btn btn-primary btn-lg", 'name' => 'report' ); echo '<span class="glyphicon glyphicon-exclamation-sign"></span> '; echo form_subm ...

Applying CSS Styles to a Single Class Only

I have been using Zurb's Foundation to customize the navbar with my own styles, which has been successful so far. However, I encountered an issue with the responsive behavior of the navbar when the viewing container size changes. The navbar adds a sec ...

When adjusting the viewport size, CSS animated elements may shift unexpectedly in Firefox and Safari, while Chrome displays them correctly

This example demonstrates a simple code snippet: body { display: flex; justify-content: center; align-items: center; height: 100vh; width: 100vw; } .container { animation: moves 5s ease 0s normal forwards; /* transform: trans ...

How can I use appendChild to place two different elements into a single div?

While exploring similar questions on this topic, I have unfortunately not come across a solution that works for me. My challenge is trying to insert two a elements inside of a newly created div element using appendChild. However, I am unable to append them ...

Overflow container list items in Bootstrap

How can I prevent the text in each item of this dropdown list from wrapping and display them in a single line? .autocomplete-items { /* position: absolute; */ /* border: 1px solid #ccc; */ /* border-top: none; */ /* border-radius: 0 0 ...

What advantages do CSS pre-processors (SASS, SCSS, LESS) bring to the table for creating Responsive Web Designs?

Currently, I am embarking on a Responsive Web Design (RWD) project and contemplating whether integrating LESS would streamline the process. Are there practical benefits to utilizing CSS preprocessors for RWD projects? I suspect that employing media qu ...

What is the best way to align the main text to the far left in a Bootstrap 4 cover template?

I am struggling to align the text to the far left of the page instead of it being centered. "Cover your page. Cover is a one-page template for creating elegant and uncomplicated home pages. Customize it by downloading, modifying the text, and inserti ...