Find and Scroll Dropdown Menu with Bootstrap Framework

Access the jsfiddle for more information. Have a look at these questions:

  1. In my dropdown menu, I have included a search box and multiple sub-menus. However, the search box only filters the first dropdown menu and does not work with the sub-menus. How can I make the search box filter all sub-menus and display their parent as shown in this image? https://i.sstatic.net/oloNY.jpg

  2. How can I add a scroll bar to my dropdown menu? I tried using overflow: auto in CSS but it made my dropdown submenu invisible like in this picture. https://i.sstatic.net/Y9NLi.jpg

  3. Is there a way to keep the dropdown submenus always on top, aligned with their respective parents? Thank you very much for your help. I am currently using bootstrap 3.3.5.

Here is the HTML code:

<nav class="navbar navbar-default navbar-fixed-top">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false"gt; 
<span class="sr-only">Toggle navigation</span>
     <span class="icon-bar"></span>
     <span class="icon-bar"></span>
     <span class="icon-bar"></span>
            </button> <a class="navbar-brand" href="#">Brand</a>
        </div>
        <!-- Collect the nav links, forms, and other content for toggling -->
        ... (omitted for brevity)
...

And the equivalent CSS code:

... (CSS code omitted for brevity)

Lastly, don't forget the JavaScript component:

$("#search-criteria").on("keyup", function () {
    var g = $(this).val().toLowerCase();
    $(".menu").each(function () {
        var s = $(this).text().toLowerCase();
        $(this).closest('.menu')[s.indexOf(g) !== -1 ? 'show' : 'hide']();
    });
});

Answer №1

Check out this CSS code snippet:

body {
    padding-top: 50px;
}
.search-box {
    margin: 5px 0px;
}
.dropdown-submenu {
    position: relative;
}
.dropdown-submenu>.dropdown-menu {
    top: 0;
    left: 100%;
    margin-top: -6px;
    margin-left: -1px;
    -webkit-border-radius: 0 6px 6px 6px;
    -moz-border-radius: 0 6px 6px;
    border-radius: 0 6px 6px 6px;
}
.dropdown-submenu:hover>.dropdown-menu {
    display: block;
}
.dropdown-submenu>a:after {
    display: block;
    content:" ";
    float: right;
    width: 0;
    height: 0;
    border-color: transparent;
    border-style: solid;
    border-width: 5px 0 5px 5px;
    border-left-color: #ccc;
    margin-top: 5px;
    margin-right: -10px;
}
.dropdown-submenu:hover>a:after {
    border-left-color: #fff;
}
.dropdown-submenu.pull-left {
    float: none;
}
.dropdown-submenu.pull-left>.dropdown-menu {
    left: -100%;
    margin-left: 10px;
    -webkit-border-radius: 6px 0 6px 6px;
    -moz-border-radius: 6px 0 6px 6px;
    border-radius: 6px 0 6px 6px;
}
#wrapper .dropdown-submenu{
    width: 200px;
    height: 100%;
    position: relative;
    overflow-x: auto;
    overflow-y: hidden;
}

#container{
    width: 300px;
    transform: translate(50px, 0);
}

View Demo on Fiddle

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

The React.js Redux reducer fails to add the item to the state

I'm just starting to learn about React.js and Redux. Currently, I am working on creating a basic shopping cart application. https://i.stack.imgur.com/BfvMY.png My goal is to have an item (such as a banana) added to the cart when clicked. (This sho ...

Exploring the world of JMeter: capturing sessions with JavaScript and jQuery

I need to capture a user session in order to conduct a performance test. I have been using the JMeter HTTP(S) Test Script Recorder, but unfortunately it is not recognizing javascript and jquery. The error message I'm receiving is: JQuery is not def ...

Exploring the Variance between 'npm run serve' and 'npm run dev' Commands in Vue.js Development

Can you explain to me the distinction between npm run serve and npm run dev in vuejs? Additionally, can you clarify why it is recommended to use the npm run serve command when running a project? ...

Eliminate inner margin from the canvas of a bar chart created with ChartJS

I am looking to use Chart.js to create a single stacked bar chart that visualizes progress towards a specific financial goal. I have added a dotted line on top of the chart to represent this goal amount. The issue I am facing is that there is unwanted pad ...

After clicking the submit button, make sure to automatically fill in all empty input fields

I am currently working on a form that includes various input types such as text fields, radio buttons, select dropdowns, and text areas. The form is displayed in a table format with an option to add additional rows. One issue I have encountered is that us ...

The CSS font-weight attribute can be set to bold or light

I've encountered a strange issue with the font-weight property when applied to a button element. When set to 400, everything functions as expected. However, attempting to set it to either 300 or 500 does not produce any noticeable changes. Interesting ...

Does Parsley.js offer a way to configure so that the parsley-success field is not added to an input if it should be completely ignored?

Currently, I am excluding one input and adding the success class (which is fine with me) $('form').parsley({ excluded: '[data-parsley-sum-total="all"]' }); However, there are several other inputs without any validations that I do not wa ...

Leveraging body-parser alongside formidable

I am currently in the process of integrating formidable to handle forms that involve file uploads (specifically images). Despite comments suggesting otherwise, I came across a comment demonstrating successful integration of both modules. This snippet show ...

Issue encountered while attempting to set up react-native project

Whenever I attempt to create a new react-native project using the command: npx react-native init myproject I encounter the following errors: ERESOLVE is overriding peer dependency npm gives me a warning while trying to resolve: [email protected] ...

"Implementing form validation and AJAX submission for seamless user interaction

I am seeking a solution to validate my form using ajax and then insert it into the database also utilizing ajax. Although, with the current code, validation messages are displayed, it still performs the insertion. The issue I am encountering seems to be ...

Having trouble with HTML tags not parsing correctly in PHP?

Similar Question: Getting a parse error: syntax error, unexpected T_STRING 59 I'm working on displaying names from a database in a table format with checkboxes. Everything seems to be functioning correctly until I try to include the input tag wit ...

The fastest method for finding the longest palindrome subsequence within a given string

I've been working on creating a function that can identify the longest palindrome subsequence within a given string. After experimenting with dynamic programming, I came up with the code snippet below: function findLongestPalindrome(str) { let lengt ...

A guide on implementing multiline properties in a property file for Selenium WebDriver

At the moment, I am focusing on utilizing Selenium WebDriver with code that is developed in Java. In the snippet below, I have successfully verified if the dropdown values match the UI for one dropdown. Now, I aim to extend this capability to check multip ...

Constant navigation bar placement

On my website, I have a fixed navigation bar at the top that I want to be transparent. However, when I apply transparency to the navigation bar, the content inside it also becomes transparent. To fix this issue, I added a relative position to the content w ...

Set the value received from the AJAX call as a global integer variable

I'm currently facing an issue in my code and struggling to find the error. I have an ajax call that executes an insert statement and returns the ID of the inserted data successfully. However, my goal is to create a global variable for this ID so that ...

Execute JavaScript script whenever the state changes

I have a large table with multiple HTML elements such as dropdowns, textboxes, radio buttons, and checkboxes. Additionally, I have a function that I want to execute whenever any of these items change. Whether it's a selection from a dropdown, typing i ...

Display dynamic text from an input field in another div along with a checkbox

In the input field below, you can type something and then click the Add button. What will happen is that the text entered in the input field will be appended with a checkbox inside a div with the class .new-option-content. For a live example, check out th ...

Using SignalR for lengthy processes: transmitting progress updates

Utilizing SignalR to initiate lengthy computations on the server and notify the client when the results are ready. The input bindings consist of an HTTP request. Desire to send multiple messages to update the client on various stages of the process (e.g., ...

Update the href attribute with values from the form fields

My current project involves creating a form with 5 input fields: Service type Number of days Number of children Number of adults I want to dynamically change the value of a button based on these variables using JavaScript. Here is my code so far: JS ...

You must use the 'new' keyword to invoke the class constructor NextResponse | Implementing middleware in Next.js | Implementing role-based protection for routes in Next.js |

I've been working on implementing user role-based protected routes in my next.js project using middleware.js, but all of a sudden, I've encountered this issue. I'm not exactly sure why this is happening, so if anyone has a better approach to ...