When the browser size shrinks, turn off the drop-down navigation menu

I'm currently working on a responsive website, and I have encountered an issue with a dropdown menu. When the browser size is reduced to 900px, the menu shifts all the way to the left side. To address this, I added some left padding to keep it off the edge until it reaches 600px. At that point, the menu transforms into a list-block view and the dropdown box disappears. My goal is to find a solution that will maintain the dropdown menu display between 600px and 900px so that it appears correctly under the intended sections. Here is a screenshot illustrating the problem.

Edit: Here's a fiddle link for reference.

Here is my code:

HTML5

<nav>
    <nav class="nav-wrapper">
        <ul>
            <li><a href="index.html">Home</a></li>
            <li><a href="appliances.html">Appliances</a></li>
            <li><a href="Electronics/index.html">Electronics</a>

                <ul>
                    <li><a href="Electronics/computers.html">Computers</a></li>
                    <li><a href="Electronics/game_systems.html">Game Systems</a></li>
                    <li><a href="Electronics/televisions.html">Televisions</a></li>
                </ul>
            </li>
            <li><a href="Furniture/index.html">Furniture</a>

                <ul>
                    <li><a href="Furniture/bedroom.html">Bedroom</a></li>
                    <li><a href="Furniture/dining_room.html">Dining Room</a></li>
                    <li><a href="Furniture/living_room.html">Living Room</a></li>
                </ul>
            </li>
            <li><a href="location.html">Location</a></li>
        </ul>
    </nav>
</nav>

CSS3

/*Default CSS*/
.main-header nav ul ul {
    display: none;
}

.main-header nav ul li:hover > ul {
    display: block;
}

.main-header nav ul {
    background: #efefef;
    background: linear-gradient(top, #efefef 0%, #bbbbbb 100%);
    background: -moz-linear-gradient(top, #efefef 0%, #bbbbbb 100%);
    background: -webkit-linear-gradient(top, #efefef 0%, #bbbbbb 100%);
    box-shadow: 0px 0px 9px rgba(0, 0, 0, 0.15);
    padding: 0 20px;
    border-radius: 10px;
    list-style: none;
    position: relative;
    display: inline-table;
}

.main-header nav ul:after {
    content:"";
    clear: both;
    display: block;
}

// Skip rest of code as it is redundant //

    /*Between 600px and 900px*/

.main-header nav ul {
    position: relative;
    margin: 0 auto;
    left: 10%;
}

.main-header nav ul ul {
    position: absolute;
    top: 100%;
}

I believe the issue lies within these two lines of code, and any assistance in resolving it would be greatly appreciated.

Answer №1

Make sure to place the absolute positioned dropdown within a relative positioned container for proper display.

.main-nav ul li {
    float: left;
    position: relative;
}

https://example.com/code-example

Further adjustments may be needed to fine-tune the positioning, but this should give you a good starting point.

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

Is there a method to use media queries to dynamically switch JavaScript files based on the user's device?

I've been working on optimizing the mobile layout of my website, and while I have successfully implemented a media query with a different stylesheet for mobile devices, I'm struggling to determine if it's feasible to also load a separate Jav ...

Is there a way to retrieve the previous value in an input field's onChange event?

I am working with inputs in a React project and have assigned a function to their onChange event. While I have been able to access the current value, I am now looking for a way to retrieve the previous value as well. The reason I need the old value is bec ...

When utilizing Xpath, it consistently triggers the Python <li> element as the first child

I am attempting to click on multiple links with the following code: self.browser.find_element_by_xpath("//li[@onclick[contains(text(),"+origin_iata_code+")]]").click() The origing_iata_code is from this list: ['FLL', 'MCO', 'AFL ...

The words spill across the navigation bar

I am facing an issue with my navbar where the text overflows and creates extra space due to a white background. I have tried resolving this for a while but haven't been successful. I need help from someone knowledgeable in this area. Here are some im ...

Creating Radial Fades with CSS3

Seeking guidance on creating a background similar to the one shown here using just CSS. I believe it can be done, but I struggle with CSS3. The goal is for the background to be compatible with all modern browsers, not overly concerned about support for br ...

Table designed using the Flexbox layout model

I am looking to create a table with multiple columns that can handle dynamic data. The challenge is that using the base <table> element would cause the column width to change when the content changes and I also need the ability to hide columns using ...

Can the typical drag and drop cursors be ignored in an HTML drag operation?

I've been working with the HTML drag and drop API to allow users to resize columns in a table. However, I've noticed that when a user starts dragging a column, the cursor changes to one of the default drag and drop effects (such as move or none). ...

What is the best way to add rounded corners to tables in Bootstrap 3?

Is there a way to give the top and bottom corners of a table rounded edges? I am currently using Bootstrap 3 tables, but they have no corner radius by default. How can I achieve this effect? ...

Is there a CSS fix for containing a floating div inside another div with overflow hidden?

I've managed to create a cool effect with a div of an airplane inside a parent div that has 'overflow: hidden' applied. This setup gives the illusion that the airplane div is flying from under an element on the page and carrying a banner alo ...

Real-time audio feed permanently stuck in Chromium-powered web browsers

Here is how the audio element appears. No interaction seems to take place with it. (Experimented on ungoogled chromium, Edge, and an android device using a default Chrome browser) Below is the HTML code for the audio element: <div> <audio co ...

"An error has occurred in the file system, make sure to handle it when

I am encountering an issue with submitting a form using jQuery's ajaxSubmit() function. The problem arises when the file selected in the form is renamed, deleted, or made inaccessible before submission, leading to potential discrepancies in whether th ...

Make the text area occupy the full width of the remaining screen space

I've been struggling to make the text area fill the remaining width of the screen. Everything is set up nicely, but I just can't seem to find a solution to get it to expand and occupy the rest of the available space. I intentionally refrained fr ...

An unexpected error has occurred in the browser console: The character '@' is not valid

I recently made the decision to dive into learning about Unit Testing with JavaScript. To aid in this process, I started using both Mocha.js and Chai.js frameworks. I downloaded the latest versions of these frameworks onto my index.html from cdnjs.com. How ...

How big is the array size in the WebAudio API data?

Exploring the visualization of waveform and FFT generated by the audio stream from the microphone through the WebAudio API. Curiosity strikes - what is the size of each data array available at a given moment? Delving into the getByteTimeDomainData, it men ...

What causes performance issues when utilizing mouseover events in JQuery?

var mouseX; var mouseY; $(document).mousemove( function(e) { mouseX = e.pageX; mouseY = e.pageY; }); $(".test").mouseover(function(){ $('#DivToShow').css({'top':mouseY,'left':mouseX, 'display':'block&ap ...

Partially filling circles for a personalized coin-slider experience

Looking to create a unique coin-slider that changes the filled factor of a coin as it moves through a specific range of images. For example, when scrolling through 10 images, the filled part of the coin would transition from 0 to 1 depending on which image ...

What is the method to execute jQuery code after the completion of a fade out effect?

I am attempting to fade out a div upon click while also adjusting some CSS properties. The problem I am encountering is that the CSS properties change during the fade out transition, instead of after it has completed. I would like the values to change onc ...

Implementing the Google Maps API into a React application to generate a customized route between two specified points

I'm currently developing a React application that is designed to display the distance between two points on a map. Although I successfully implemented this feature using JavaScript and HTML, I am facing challenges in converting it to React as I am re ...

The inefficiency of invoking Jquery on elements that do not exist for the purpose of caching

What is the impact if JQuery attempts to access elements that do not exist? Will there be any significant CPU overhead other than script loading? Does it matter if this is done for a class or an id? For optimization purposes and to minimize simultaneous c ...

Do you have any recommendations for a creative CSS method to achieve a full-screen background image?

After searching online and experimenting with different methods, I have yet to discover a solution that suits my needs. My goal is to have the background image on my website centered, filling the entire browser screen, while also being compatible with resp ...