Header navigation issue: sub menu fails to display

I've been trying to troubleshoot this issue, but nothing seems to quite fit my situation.

My header contains an empty space (referred to as "void" in my case) and a menu directly beneath it.

When scrolling down, the header moves up and the menu remains fixed at the top of the screen as expected.

Everything is functioning fine so far.

The problem arises with the submenu within the menu. The submenu only functions properly when the menu is not fixed at the top of the screen.

I understand that the submenu should have a "fixed" position when the menu is also "fixed," but despite my efforts, it just isn't working. The submenu does become fixed, but then it disappears behind the rest of the page, regardless of the z-index I assign to it or any other component on the page.

I feel like I've exhausted all possible solutions and I'm stuck.

I created a JSFiddle where you can test my script. To reproduce the bug, hover over the menu when the header is not fixed, and then do the same after scrolling down. It works when the menu is not fixed, but the submenu fails to appear when it is.

Thank you for your assistance.

HTML

<header>
    <div class="void"></div>
    <nav class="menu">
        <ul class="block">
            <li class="item">xxxxx</li>
            <li class="item">xxxxx</li>
            <li class="item drop">Hover here
                <div class="dropdown-content">
                    <a href="">submenu 1</a>
                    <a href="">submenu 2</a>
                </div>
            </li>
            <li class="item">xxxxxx</li>
        </ul>
    </nav>
</header>

CSS

body{
    width:100%;
    height:6000px;
    margin:0px;
    padding:0px;
    background: #ccc;
}

header{
    position:relative;
    width:100%;
    background: #fff;
    z-index:1;
    height:146px;
}

.void{
    position:relative;
    width:100%;
    height:100px;
}

.menu{
    position:relative;
    width:100%;
    height:54px;
    background:#aaa;
}

.menu ul{
    height:100%;
    margin:0px;
    padding:0px;
    display:flex;
    flex-wrap: nowrap;
    justify-content: space-between;
}

.item{
    display:inline-block;
    flex-direction: column;
    height:100%;
    color:#41546F;
    line-height:54px;
    font-size:13px;
}

.block {
    position: relative;
    z-index:1;
}

.dropdown-content {
    display: none;
    position: absolute;
    min-width: 140px;
    z-index: 1;
    margin-left:-40px;
    margin-top:0px;
    background:#21242b;
    padding:16px;
}

.dropdown-content a {
    display: block;
    color:#a2a9b9;
    line-height:32px;
}

.drop a:hover {
    color: #fff;
}

.drop:hover .dropdown-content {
    display: block;
}

.fixed{
    position: fixed;
    overflow: hidden;
    left:0px;
    top: 0px;
}

JQUERY

$(window).scroll(function() {
    if ($(document).scrollTop() > 92){
        if (!$('.fixed').length){$('.menu').addClass('fixed');}
    } 
    else {
        if ($('.fixed').length){$('.menu').removeClass('fixed');}                  
    }     
});

JSFiddle

https://jsfiddle.net/3xnjeh01/

Answer №1

The problem lies with the overflow: hidden property applied to the .fixed class.
This is causing the submenu to be hidden, simply remove this property.

.fixed {
    position: fixed;
    left: 0;
    top: 0;
}

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

Customize HTML styles using Angular Material

I've noticed that my index.html file has a lot of style elements when using Angular Material, and I'm not sure why. Here's an example in the header element where different classes are used for Angular Material components. https://i.sstatic. ...

ZeroClipboard intricate CSS issue

I have a list of images with an option box that appears on mouseover. The box contains an embedded code input field for copying purposes. I recently implemented zeroclipboard to enable the copy function on click. However, when I hover over an image and try ...

Unable to choose multiple options within a selection field

My webgui testing involves the use of selenium, which includes the following method: protected static selectListItems(String id, String value1, String value2, String value3,String value4){ String values = "" if(StringUtils.isNotBlank(value1)) ...

Utilizing Ajax and Jquery within Zend framework

I'm working with the Zend framework using PHP and attempting to submit a form via ajax/jquery. Below is the structure of the .phtml file: <form id="find"> <input type="text" name="name"> <input type="submit" id="submit" value ...

Reposition the navbar-brand

I need to adjust the position of my navbar-brand slightly to the right as it is currently overlapping with another button. How can I achieve this in my HTML code? Here's a snippet: <nav class="navbar navbar-expand-lg navbar-light bg-light"> ...

Tips for achieving an HTML anchor effect using jQuery

In my click handler, I use "event.preventDefault" to prevent the default behavior. After a series of complex logic, I want the page to smoothly scroll back up to the top as if it were anchored. $('.vod-playlist-film a').bind("click", function(ev ...

Is it possible to enlarge the window screen using css?

After using zoom at 90%, everything was working fine until we introduced high charts. The hovering property doesn't display in the correct position. Looking for a solution to show a zoomed window on a small screen, like a laptop screen. Does anyone h ...

Employ JQuery to create a smooth fading effect on a button when hovering over it, and then gradually fade it out

Is there a way to make a button fade in when I hover over an image and then disappear once I hover off? I have tried using the hover() function with a button class of "goto" (#goto), but can't seem to get it to work. Would combining fadein and fadeout ...

Combining Python strings

I'm trying to understand the distinction between two statements. I need to display a variable in a <p> HTML tag. Both statements achieve the same outcome, but one is causing an error. The first statement that functions correctly: out += "</ ...

What is the best way to capture videos using Safari?

Hey there! I've set up the browser camera on my website for users to record live tests. It's been working great on Chrome and Firefox using MediaRecorder, but unfortunately, Safari isn't cooperating. Does anyone know of an alternative to Me ...

Changing CSS module variables through JavaScript programming

I'm currently utilizing an older version of react-boilerplate that includes CSS Modules, allowing for the creation of variables and the ability to import them into other CSS files. Below is my colors.css file: :root { /* Status colors */ --error ...

Unfocus element in IE11

Currently, I am dealing with an issue involving the following image: The main problem arises when the jQuery UI tooltip fails to close properly after I close a modal window that was opened by clicking on the link associated with the tooltip. Interestingl ...

How can we separate XML data retrieved from an Ajax call using jQuery?

I have a massive amount of data from an XML file that I am organizing into an unordered list. I need to split the data into multiple lists so that I can style them as columns using CSS. Is there a way to insert a </ul><ul> every 20 entries or s ...

implement a Django for loop within the template by utilizing JavaScript

Is it possible to incorporate a {% for in %} loop and {{ variables }} in a Django template using JavaScript DOM (insertAdjacentText, or textContent) and dynamically load data from the views without refreshing the entire page? If so, can you please guide me ...

Guide on utilizing AJAX and Jquery for redirection purposes

I am a beginner in Ajax and I came across this question before, but I am experiencing an issue in the Chrome console. Here is the PHP code snippet: $rs1 = [ 'error' => $blank_err, 'url' => "http://localhost/expe ...

How to hide or remove an element in jQuery depending on an attribute change

I am currently working on my website and exploring ways to utilize jQuery to display or add the element div#content1 when the #nav-home-tab has aria-selected=true, and to hide or remove the element if aria-selected=false. This is what I have tried so far: ...

How can I display data saved from step 2 in a multi-step form with 4 steps, when I return from step 3 to step 2?

Let's consider this scenario: Imagine the user is at step 2 and types their name into <input type="text" class="form-control input-xl" ngModel name="firstName"> They proceed to step 3 but then decide to return to step 2. The information entere ...

Is the form data in AngularJS not submitting correctly?

Why is my HTML form data not being submitted using POST method? HTML View Page:- <div class="col-sm-12"> <div class="card-box"> <form class="form-inline" name="addstock" ng-submit="saveStockPurchaseInvoice()"> <h ...

Adjust the color of a label based on a set threshold in Chart.js

Can anyone help me with my Chart.js issue? Here is a link to the chart: https://i.sstatic.net/RL3w4.gif I am trying to change the color of the horizontal label when it falls between 70.00 - 73.99. Does anyone know if there's a specific option for th ...

Ajax-powered Wordpress Meta Box

For this project, I plan on incorporating a WordPress meta box by calling wp_ajax. I attempted to implement this feature, but unfortunately, it is not working as expected. add_action('add_meta_boxes', 'add_custom_meta_box', 'post ...