Tips for displaying a navbar dropdown menu outside of its container

Before encountering this issue, I was struggling with making the navbar scroll on smaller screens when expanded. I found a helpful solution on Stack Overflow: responsive fixed-top navbar when expanded fills up screen, hides some of the nav-links, and does not scroll

After implementing the answer from that question, I managed to make the navbar scroll. However, a new problem arose. When clicking on a navbar link, the dropdown menu that appeared would remain within the navbar container and wouldn't scroll along with the navbar.

I have included an image to illustrate this issue: https://i.sstatic.net/lofON.png

Here is the CSS code I used to enable scrolling for the collapsed navbar:

.fixed-top .navbar-collapse {
    max-height: calc(100vh - 4.5em);
    overflow-y: auto;
}

Everything works fine when the navbar is collapsed, but on larger screens, the dropdown menu remains within the container. How can I make the dropdown menu appear outside the navbar container?

You can view a JSFiddle demonstrating this issue here: https://jsfiddle.net/suhaib47/7b58o0d3/3/
Please note that the viewport width should be wide enough to display the full navbar. Click on the OLE dropdown and then scroll down to view the dropdown menu.


When I attempt to show the dropdown menu outside the container, it becomes unscrollable on smaller screens. Conversely, when the menu is scrollable, it remains within the nav container.

How can I achieve the goal of having the dropdown menu appear outside the navbar container while maintaining scrollability for the responsive navbar on smaller screens?

I came across a similar question on Stack Overflow, but the solution provided did not solve my issue: The navbar dropdown menu does not beyond the container

Answer №1

Initially, I had hoped to find a solution for this issue that did not require the use of media queries. However, I eventually managed to resolve it by implementing a media query.

@media only screen and (max-height: 450px) {
    .fixed-top .navbar-collapse {
        max-height: calc(100vh - 4.5em);
        overflow-y: auto;
    }
}

By utilizing this approach, scrolling functionality is now available as needed, based on the screen size and orientation, specifically when the navbar menu is collapsed.

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

Display an image with a colored background using CSS

Most of you have probably noticed that images on Facebook come with a default background. How can I achieve a similar background color for images without using an additional div just for the background? My current codes do create a background color, but th ...

Encountering an Issue with Incorporating Multiple SCSS files in Jekyll

Currently, I am in the process of developing a website using Jekyll. My goal is to incorporate multiple SCSS files into the project. Although I successfully added a main file, I have encountered some difficulties with additional files. Here is my director ...

Having difficulty choosing a drop-down menu option with AJAX technology

My current project involves creating a page where the database is updated upon a drag-and-drop event. Specifically, I have implemented drag-and-drop functionality on a page, and whenever a div (deal-card) is dragged and dropped into another div (stage-colu ...

The input field does not accept any values even after setting it to be editable

Hey there! I have a specific requirement where I need to edit certain fields by clicking on an edit link. Initially, these fields will be disabled and in a readonly state. Once I click on the edit link, the field should become blank and editable. The issu ...

Having trouble with CSS basics? Seeing properties change across multiple classes?

My CSS skills are still in the beginner stage and I am currently struggling to troubleshoot an issue with my code. The HTML: <div id="loginForm"> <span class="dottedLink"><a href="resetlogin">Recover login details</a></span ...

The HTML code for the base64 image conversion failed to load

I am facing an issue with handling HTML strings containing base64 image tags generated by Summernote. I have a process in place where I load the image elements, convert them to image blobs, upload them to get the image-url, and then update the src attribut ...

Streaming Ogg audio from a PHP file is not possible to seek in Chrome

As I work on creating a basic audio player using the HTML5 audio element, the files being served are in .ogg format coming from another system as a binary string through an API. They are then processed by a simple PHP handler that includes some security ch ...

How can you ensure that divs stay the same size and appear next to each other without resorting to using

I need assistance with organizing my website layout as shown below: https://i.sstatic.net/Dpof9.png The image div will display an image of variable size, which needs to be vertically and horizontally centered. The text div will contain a large amount of ...

Streamline the Bootstrap 4 Card Component by eliminating any unnecessary whitespace

Currently I am utilizing the card component from BS4, but it seems to be displaying unexpected behavior: see the image description here Upon inspecting the Mozilla dev version, the following markup is visible: <div class="right- ...

Design a div element with a responsive aspect ratio of 16:9

Hey everyone, I've been working on creating a responsive div with a 16:9 ratio. However, I've noticed that when I resize the window, the container3 remains the same size. Can anyone spot an issue in my code and offer some help? Thanks! $(docum ...

Ways to restrict access to resources

My static website is simple, but I am concerned that everyone has access to my assets. For example, when I go to www.mysite.com/assets in the browser, it shows: Index of /assets Parent Directory css/ img/ js/ Is there a way to display a 403 error page ...

Ways to evaluate the amount of traffic on a webpage?

Recently, I encountered an issue while creating a page to showcase blog posts. Each post had the typical social media share buttons like "Facebook like," "tweet this post," and "+1." Additionally, there were some extra JavaScript functions added for variou ...

A guide to using JavaScript to restrict the textarea's height while allowing it to expand dynamically and setting a maximum height

Seeking assistance with a challenge I have encountered and unsure how to resolve. Any help would be greatly appreciated! The issue at hand is as follows: I am currently working on a textarea. My goal is to have the input box start with a height of 36px, ...

The jQuery ellipsis extension is incompatible with the "max-height" property

Is it possible to use this plugin with the "max-height" css property? Currently, it only works with a specific height defined but not with max-height. Is there a way to make it compatible with max-height as well? (function($) { $.fn.ellipsis = f ...

Arrange divs in a stack when one becomes too full

Struggling to find a pure CSS solution for this issue, so seeking advice. Imagine three divs aligned horizontally next to each other. If one div overflows onto the next line, I want them to switch to a vertical stack layout. How can this be achieved? I h ...

Interactive Javascript dropdown helper on change

I am currently experimenting with a JavaScript onchange method, as I am relatively new to coding. My goal is that when I select "ID Type," the input text should change to "passport," and when I select "South African ID," the input should switch to "South ...

Steps to insert a column within an HTML document for PDF printing

Is there a way to create an HTML document that can be printed in PDF format but the column feature isn't functioning as expected? Would I need to use a specific library or tool? ...

Changing the image source using Javascript and extracting part of the URL

i'm attempting to extract the image url from a series of urls in a loop, removing the hash portion () without the hash (?sqp=-oaymwEjCNACELwBSFryq4qpAxUIARUAAAAAGAElAADIQj0AgKJDeAE=&rs=AOn4CLDi79vN15idfFETvntyC9yat7FvZQ). I've managed to mak ...

What is the best way to use ajax to load a particular div or class from a file?

In my main.html file, there are several divs each with 2 classes. The first is their specific class and the second is a class called menu-item, which determines if an event will be triggered when clicked. For example: <div id="load-here"> </div ...

Struggling to use GSAP to control the timeline with my custom functions

I'm attempting to create a greensock animated banner with the ability to switch between different scenes. I've made progress by setting up the timeline for each scene's intro and outro animations using the GreenSock API documentation. Howeve ...