Position dropdowns side by side within a Bootstrap navigation bar

Struggling with utilizing Bootstrap's nav-bar component - I'm attempting to position two dropdowns next to each other on the left side of the viewport. The Bootstrap framework being used is right-to-left (rtl). Here's an example of the navbar structure:

<nav class="navbar fixed-top navbar-expand-sm navbar-dark">

    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>
    <!-- Links -->
    <div class="collapse navbar-collapse justify-content-between" id="navbarSupportedContent">
        <ul class="navbar-nav float-right">
            <li class="nav-item">
                <a class="nav-link" href="#">Link 1</a>
            </li>
          
        </ul>
        <div class="bg-danger flex-row">
            <ul class="navbar-nav">
                <li class="nav-item dropdown ">
                    <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button"
                       data-toggle="dropdown"
                       aria-haspopup="true" aria-expanded="false">
                        Dropdown
                    </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>
            <ul class="navbar-nav">
                <li class="nav-item dropdown ">
                    <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown1" role="button"
                       data-toggle="dropdown"
                       aria-haspopup="true" aria-expanded="false">
                        Dropdown
                    </a>
                    <div class="dropdown-menu" aria-labelledby="navbarDropdown1">
                        <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>
        </div>
    </div>
</nav>

Looking to align two dropdowns with .bg-danger styling so that their links are positioned adjacent to each other. How can this be achieved?

Answer №1

Take a look at the HTML code below, where both <li> elements are placed inside a single <ul>:

<nav class="navbar fixed-top navbar-expand-sm navbar-dark">

    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>
    <!-- Links -->
    <div class="collapse navbar-collapse justify-content-between" id="navbarSupportedContent">
        <ul class="navbar-nav float-right">
            <li class="nav-item">
                <a class="nav-link" href="#">Link 1</a>
            </li>

        </ul>
        <div class="bg-danger flex-row">
            <ul class="navbar-nav">
                <li class="nav-item dropdown ">
                    <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button"
                       data-toggle="dropdown"
                       aria-haspopup="true" aria-expanded="false">
                        Dropdown
                    </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>
                <li class="nav-item dropdown ">
                    <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown1" role="button"
                       data-toggle="dropdown"
                       aria-haspopup="true" aria-expanded="false">
                        Dropdown
                    </a>
                    <div class="dropdown-menu" aria-labelledby="navbarDropdown1">
                        <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>
        </div>
    </div>
</nav>

If you encounter any problems, feel free to reach out.

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

Place Div in the center of another Div

In my maze creation, I am trying to center an inner div, but no matter what I do, using margin: 0 auto; does not seem to work The inner div displays a sad smiley face when the user enters a wall and loses #highlight_lose { width: 550px; height:55 ...

Unable to scroll after the webpage redirects

I am currently working on developing a website for uploading images with a comment feature. The comments section is displayed below the image in the 'imagedisplay.php' file. If a user is not logged in, they are redirected to the sign-up page and ...

Rendering High-quality Images in Internet Explorer Browser

Currently, I am working on optimizing my website for high resolution monitors, particularly the new iPad. The site is already formatted to my liking, with images having increased resolutions while still fitting into specific DIVs. For instance, an image wi ...

The color of active links in TailwindCSS remains unchanged

In my project, I am using NextJS along with Tailwind CSS to create a top navigation bar. My goal is to change the text color for active links within the navigation bar. Below is the code snippet I have implemented: const Header = () => { return( ...

Retrieving text content from the h1 element's class name

Trying to extract the text 'getthis' using the agility pack. <h1 class="point">getthis< span class="level">Niveau 0</span> </h1> Tried methods: var links = webBrowser1.Document.GetElementsByTagName("point"); foreach ...

PHP: Showing the content of every div on the page

I am facing an issue with retrieving input values from multiple divs in the HTML code provided below. Specifically, I want to extract the Input values with the name LI_Dept as an array for each individual div when handling data in PHP. Is there a way to f ...

Adding a dynamic form to each row in a table: A step-by-step guide

https://i.sstatic.net/HctnU.jpg Hey there! I'm facing a challenge with dynamically generated rows in a form. I want to send only the inputs from the selected row when a checkbox is clicked. Can you help me figure this out? I tried using let rowForm ...

What is the correct way to utilize window.scrollY effectively in my code?

Is it possible to have a fixed header that only appears when the user scrolls up, instead of being fixed at the top by default? I've tried using the "fixed" property but it ends up blocking the white stick at the top. Adjusting the z-index doesn&apos ...

What is the best way to nest a div within a flexbox container?

I am attempting to create a div that is based on percentages, and I want to nest a div inside another. Specifically, I want the center (xyz div) to only take up 90% of the height of the content-div. My goal is for the "content" div to be responsive to 90% ...

Is there a way to adjust the position of ion-content dynamically? Can this be done?

Having an issue, let's take a look at the structure <ion-view> <ion-header-bar class="bar-subheader"> </ion-header-bar> <ion-content class="has-header has-subheader has-footer"> </ion-content> <i ...

Accessing the data from an HTML5 slider using JQuery

Having some difficulty fetching a value from an HTML5 slider using JQuery. Here is my code snippet: JQuery Code: // Getting the value from slider one $("#submit").on("click", function(evt) { var sliderValue = $('#slider01').attr('value ...

Issue with font-size changes using css variables in Angular not updating in browser for specific fields

Utilizing CSS variables, I have implemented a feature that allows users to adjust the font size to small, medium, or large. While this functionality works correctly for most fields, there are certain instances where the value is applied but not displayed. ...

What are the steps to create an endless scrolling feature?

I'm trying to create a slider with a horizontal scrolling effect, but I've hit a roadblock. How can I make the slider scroll infinitely? In my code, you can see that after Item 6, it stops scrolling and I have to scroll backward. However, I want ...

Tips for converting an Elementor section into a clickable button

Link: I have a section on my website that I want to turn into clickable buttons. Using WordPress with the Elementor plugin, I have already added some custom CSS to make it appear clickable, but now I need to add the actual functionality. I know that JavaS ...

Is it possible to transfer my Bubble webpage to another hosting server?

Can I export the "Code" from bubble.io to create my own server? Appreciate any help! ...

Simultaneous display of icon and text on Bootstrap toggle button

Currently, I am utilizing Bootstrap 3 along with Jquery. Within my coding structure, there is a button that holds an icon within a span tag (specifically using the glyphicon provided by Bootstrap). <button id="swapArchived" class="btn btn-default btn-s ...

Choose the section of the date input that represents the day

Is there a way to focus an HTML input element with type="date" and select only the day part of the date? I attempted: $("#entry-date-text").focus(); var dt = $("#entry-date-text")[0]; dt.setSelectionRange(3, 5); However, this resulted in the following e ...

Tips for selecting an element within a span by clicking on it?

Is there a way to click on an element that is contained within a span tag? I have attached a screenshot for reference. https://i.sstatic.net/FkhDB.jpg I would greatly appreciate any help on how to successfully click on that specific element. ...

What could be causing my HTML footer to not grow from its borders?

Hello there, I need assistance with an HTML document I am working on. Can you explain why my footer is not expanding to the edges even though I have set the width to 100%? Please help. Please note that the code provided is incomplete, and for the full cont ...

Updating images based on dropdown selection using Bootstrap

Can you provide guidance on changing the img src (<img src="img/website_building.jpg"...) within a Bootstrap dropdown list based on item selection? Is this functionality achievable? <tr> <td class="bold text-primary"> ...