Is it possible to nest a bootstrap "btn-toolbar" to create horizontal scrolling on smaller screens with Bootstrap 4?

I am utilizing the "btn-toolbar" class from bootstrap to contain multiple "btn-group" class dropdown buttons on a single line. For smaller screens, I want the btn-toolbar div to have a fixed width so that it can be horizontally scrollable. To achieve this, I need a parent div to enclose the "btn-toolbar" and apply CSS property overflow-x: scroll, allowing the btn-toolbar to maintain its width off-screen.

The main problem arises when the parent div is added, as the dropdown menus end up partially obscured behind the parent div. If I remove the parent div (and consequently lose the horizontal scrolling ability), everything functions properly. The issue also disappears when using direct sibling divs. Is there a way to adjust the elements involved to retain the parent div?

Please share any suggestions you may have!

I have attempted adjusting the z-index of all related divs and dynamic classes associated with the dropdown.

<div class="wrapper">
  <div class="btn-toolbar" role="toolbar">
     <div class="btn-group">
        <button class="btn btn-outline-primary dropdown-toggle" 
           type="button" id="dropdownMenuButton" data- 
           toggle="dropdown" aria-haspopup="true" aria- 
           expanded="false">
                Dropdown button
         </button>
         <div class="dropdown-menu" aria- 
            labelledby="dropdownMenuButton">
            <a class="dropdown-item" href="#">Action</a>
            <a class="dropdown-item" href="#">Another action</a>
            <a class="dropdown-item" href="#">Something else 
              here</a>
    </div>
  </div>
</div>

.wrapper {
    width: 100%;
    overflow-x: scroll;
    border-bottom: solid 1px #ccc;
}

.wrapper::-webkit-scrollbar { 
    display: none; 
} 

.btn-toolbar{
    min-width: 1000px;
}

.btn-toolbar button {
    padding: 2px 8px;
    margin: 8px 5px;
    color: #1eafed;
    border-color: #1eafed;
}

Anticipated behavior was for the dropdowns to appear correctly when triggered, instead, they are hidden behind the bottom part of the wrapper div (which is only around 50px tall).

Answer №1

The dropdown menu that appears is set with the property 'position:absolute', meaning it will stay within the boundaries of its parent element... and inside the parent class wrapper, you had specified overflow-x: scroll;;

To override this, we needed to modify the position:absolute property, which we accomplished by using the following code snippet:

.wrapper > .btn-toolbar > .show > .show { position:fixed !important;     left: auto !important; }

See the complete working example below:

.wrapper {
  width: 100%;
  overflow-x: scroll;
  border-bottom: solid 1px #ccc;
}

.wrapper::-webkit-scrollbar {
  display: none;
}

.btn-toolbar {
  min-width: 1000px;
}

.btn-toolbar button {
  padding: 2px 8px;
  margin: 8px 5px;
  color: #1eafed;
  border-color: #1eafed;
}

.wrapper>.btn-toolbar>.show>.show {
  position: fixed !important;
  left: auto !important;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>


<div class="wrapper">
  <div class="btn-toolbar" role="toolbar">
    <div class="btn-group">
      <button class="btn btn-outline-primary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria- expanded="false">
                Dropdown button
         </button>
      <div class="dropdown-menu" aria- labelledby="dropdownMenuButton">
        <a class="dropdown-item" href="#">Action</a>
        <a class="dropdown-item" href="#">Another action</a>
        <a class="dropdown-item" href="#">Something else 
              here</a>
      </div>
    </div>
    <div class="btn-group">
      <button class="btn btn-outline-primary dropdown-toggle" type="button" id="dropdownMenuButton2" data-toggle="dropdown" aria-haspopup="true" aria- expanded="false">
                Dropdown button #2
         </button>
      <div class="dropdown-menu" aria- labelledby="dropdownMenuButton2">
        <a class="dropdown-item" href="#">2 - Action</a>
        <a class="dropdown-item" href="#">2 - Another action</a>
        <a class="dropdown-item" href="#">2 - Something else here</a>
      </div>
    </div>
  </div>
</div>

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

Utilizing Scrollify for seamless section scrolling with overflow effects

I have been experimenting with the Scrollify script (https://github.com/lukehaas/Scrollify) and facing an issue where my sections are longer than the user's screen, requiring them to scroll down to view all content. However, Scrollify doesn't al ...

Having trouble toggling the dropdown submenu feature in a Vuejs application?

.dropdown-submenu { position: relative; } .dropdown-submenu .dropdown-menu { top: 0; left: 100%; margin-top: -1px; } <div class="dropdown"> <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown">Tutorial ...

Execute a single test from a particular test suite using Jest

Within my file named "test-file-1", I have several describes (test suites) with distinct names, each containing tests that may share similar names across different test suites. In order to run a single test suite or test, I enter the following command: n ...

Utilizing local storage functionality within AngularJS

I've been encountering challenges while trying to integrate local storage using ngStorage in my ongoing AngularJS project. Despite fixing what seems to be the root cause of data type problems and errors during debugging, issues persist. Here is the P ...

Ajax: Failed to send POST request (404)

After adding a POST script in the manage.ejs file and console logging the data to confirm its functionality, I encountered an issue. Below is the code snippet: <script type="text/javascript"> var guildID = "<%= guild.id %>"; let data = {so ...

Convert a pandas dataframe into a JSON object with nested structures

Someone raised a similar question in a different forum, which was expertly answered by user1609452 using R. However, I believe there is more to explore with this topic. Let's consider a table (MyData) that looks like this: ID Location L_size L_co ...

Drawing mysteriously disappeared from the canvas

Having trouble with my JavaScript code. I created a function called drawLine to trace lines on a canvas from one point (x,y) to another point (xdest, ydest). The first few lines display correctly but after the fourth line, it stops working and I can't ...

Inject the code snippet from CodePen into a WordPress webpage

I have a WordPress page where I want to integrate the HTML, CSS and JS code from my Codepen project. The styling appears to be working correctly, but the JavaScript is not functioning as expected. You can view the page here: Could someone assist me in pr ...

ISP Blocks Flash Access

My innovative set of flash games has been adopted by numerous schools throughout the UK. However, I recently encountered an issue where one school was unable to load these Flash games... After reaching out to the school's Internet Service Provider (S ...

Can someone assist me in figuring out why the ShowDetail.html page is not opening after I submit my form?

I'm having trouble getting the shoDetail.html page to open when I submit the code. I even tried entering the complete URL, but it still won't work. Here is the code I am using: <div class="form-group row"> <div class="col-lg-12 col-md-1 ...

Navigating deprecated CanActivate in Angular-15 with Auth Guard

Authentication Guard: import { Injectable, inject } from '@angular/core'; import { ActivatedRouteSnapshot, CanActivate, CanActivateFn, Router, RouterStateSnapshot, UrlTree } from '@angular/router'; import { Observable } from 'rxjs& ...

Removing   from a text node using JavaScript DOM

I am currently working with xhtml in javascript. To retrieve the text content of a div node, I am concatenating the nodeValue from all child nodes where nodeType is Node.TEXT_NODE. However, sometimes the resulting string includes a non-breaking space enti ...

Is it possible to use jQuery validate for remote parsing with two fields in a single call

Currently, I am facing an issue while trying to parse two values using jQuery's validate plugin to compare with an SQL database. The DateReceived value is successfully parsed, but the CentreID value always appears as null. Below is the code snippet I ...

Deactivate a few CSS guidelines

For my project, I am incorporating interfaces within other interfaces and have been facing conflicts between bootstrap rules and other CSS files. To address this, I encapsulated all Bootstrap rules within a .use_bootstrap class. Now, within my interfaces ...

Deserialization does not support the use of Type System.Collections.Generic.IDictionary for an array

An issue might arise when trying to call a page method using a manually created JQuery.ajax request. The deserialization process is handled by .NET and not within the user's code. Javascript: MyParam = []; ... $.ajax({ type: 'POST', ...

Adjusting the maximum width of a Bootstrap container

I am currently working on a login page project using Bootstrap 4 and I have a question regarding the max width of containers with Bootstrap. It appears that the maximum width is set to 1140px by default, but my monitor has a resolution of 1920px. Do I need ...

A guide on changing the background color to complement the light/dark theme in Bootstrap 5.3

In the latest version of Bootstrap, 5.3, users have the ability to select a theme for their websites. The built-in options include a Dark theme and a Light theme. For instance, by setting <html data-bs-theme="dark">, you can specify that t ...

What steps do you need to take in order to transform this individual slideshow script into numerous slideshows

I came across this code online that effectively creates a slideshow. https://css-tricks.com/snippets/jquery/simple-auto-playing-slideshow/ Is there a way to modify the code to support multiple slideshows? I've made several attempts without success ...

Is there a way to detect when the browser's back button is clicked?

As I work on supporting an e-commerce app that deals with creating and submitting orders, a user recently discovered a loophole wherein they could trigger an error condition by quickly pressing the back button after submitting their order. To address this ...

What could be causing express to have trouble finding the ejs file in the views directory?

Recently delved into the world of learning NodeJS and Express. // Working with express framework var express = require("express"); var app = express(); app.get("/", (req,res) => { res.render("home.ejs"); }) //Setting up port listening app.listen ...