How to Create a Hover Drop Down Menu that Disappears When Not Hovered Over

When I hover over the drop down menus on my Navbar, they display perfectly. However, it's impossible to click on the items in the menu because as soon as I move the cursor away from the main nav, it disappears. I've tried adding display:block and z-index properties, but the problem persists.

CSS


    #ime-nav {
position: fixed;
width: 100%;
z-index: 10000;
background:#FF9900;

}


#ime-nav ul {
    list-style-type:none;
    margin:0;
    padding:0;
    position: fixed;

}

#ime-nav li {
    display:inline-block;
    float: left;
    margin-right: 0px;
    alignment-adjust:central;
}

#ime-nav li a {
    display:block;
    min-width:195px;
    height: 50px;
    text-align: center;
    line-height: 50px;
    font-family: 'PT Sans Narrow', Arial, sans-serif;
    color: #fff;
    background: #2f3036;
    text-decoration: none;
}

#ime-nav li:hover a {
    background: #F7931E;
}

#ime-nav li:hover ul  a {
    background: #f3f3f3;
    color: #2f3036;
    height: 50px;
    line-height: 40px;
}

#ime-nav li:hover ul a:hover {
    background: #333333;
    color: #fff;


}

#ime-nav li ul {
    display: none;
}

#ime-nav li ul li {
    display: block;
    float: none;
}

#ime-nav li ul li a {
    width: auto;
    min-width: 100px;
    padding: 0 20px;
}

#ime-nav ul li a:hover + .hidden, .hidden:hover {
    display: block;

/*this is where I'm trying to fix the problem*/ 

}

.show-menu {
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    text-decoration: none;
    color: #fff;
    background: #333;
    text-align: center;
    padding: 10px 0;
    display: none;
}

input[type=checkbox]{
    display: none;
}

input[type=checkbox]:checked ~ #menu{
    display: block;
}


@media screen and (max-width : 760px){

    #ime-nav ul {
        position: static;
        display: none;
    }
    #ime-nav li {
        margin-bottom: 1px;
    }
    #ime-nav ul li, li a {
        width: 100%;
    }
    #ime-nav .show-menu {
        display:block;
    }
}

HTML

    
<div id="ime-nav">
    <label for="show-menu" class="show-menu"><img src="navigate.png" /></label>
    <input type="checkbox" id="show-menu" role="button">
        <ul id="menu">
        <li>
            <a href="#"><img src="icon_nav.png" /></a>
            <ul class="hidden">
                <li><a href="#"><img src="nav_libraryicon.png" /></a></li>
            </ul>
        </li>
        <li>
            <a href="#">Home ↓</a>
            <ul class="hidden">
                <li><a href="#">News and Articles</a></li>
                <li><a href="#">Photo Gallery</a></li>
            </ul>
        </li>
        <li>
            <a href="#">Library ↓</a>
            <ul class="hidden">
                <li><a href="#">Thermal Power Library</a></li>
                <li><a href="#">Mechatronics Library</a></li>
                <li><a href="#">Freshman Library</a></li>
                <li><a href="#">Main Library</a></li>
            </ul>
        </li>

        <li>
            <a href="#">Learn ↓</a>
            <ul class="hidden">
                <li><a href="#">Pro Engineer/ Creo</a></li>
                <li><a href="#">Autocad</a></li>
                <li><a href="#">Matlab </a></li>
                <li><a href="#">Microsoft Excel</a></li>
                <li><a href="#">Lab Episodes</a></li>
            </ul>
        </li>

        <li><a href="#">Virtual Registration</a></li>
        <li><a href="#">Contact Us</a></li>
        <li><a href="#">About Us</a></li>



    </ul>



  </div>
  </div>

Answer №1

Instead of using this code snippet

 #ime-nav ul li a:hover + .hidden, .hidden:hover {
   display: block;
   /*this is where I'm trying to fix the problem*/ 
 }

Try implementing it like this instead

 #ime-nav ul li:hover ul{display:block}

Check out the DEMO here

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

Collapsed Bootstrap 5 select drop-down featuring the multiple attribute

I am facing a challenge with using the select element along with the 'multiple' attribute. My aim is to have it collapsed by default and expand only when the user clicks on it. Unfortunately, Bootstrap 5 no longer supports the multiselect feature ...

Is it possible to have an iframe set in the background with a specific z-index but without

Currently, I am working on a webpage where I have inserted an iframe in the background because other div elements on the page "interact with it". Even though I have used z-index to make it visible in the background, I am facing issues with controlling it s ...

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 ...

Prevent the hover() effect from affecting all div elements at once

I am aiming to achieve a function where hovering over a div with the "rectangle" class will display another div with the "description" class. Initially, the description div will have a display value of "none", but upon hovering, it should become visible. ...

arranging the divs based on the space allocation within the page

Is there a way to neatly organize the divs on a page, depending on available space? I want them to align horizontally if there is enough room before moving to the next line. The tab-content parent div may contain several divs. Any suggestions on how this c ...

Having trouble with syntax highlighting on Node.js Vash view files in Visual Studio 2015 Update 3?

While working on a Node.js application using Vash as the view engine in Visual Studio 2015 Update 3, I encountered an issue with syntax highlighting. When writing HTML in the vash files, the code appears as plain text without any syntax highlighting. For e ...

Adjust parent div size automatically when child is resized - jQuery Resizable Plugin

I need some assistance with jQueryUI Resizable. How can I resize only the height of the parent div when the child div is resized and touches the bottom end of the parent div? Additionally, I want to ensure that the child div does not go outside the boundar ...

Using jQuery to swap out intricate background designs

I'm attempting to use jQuery to change the background-color of an element from: background: transparent linear-gradient(#C0B 45%, #C0B) to: background-color:#000; Unfortunately, my attempt to remove the background property with .removeAttr() has n ...

Is there a way to arrange the outcomes in a single line?

I need help displaying my results in three rows side by side in React/JavaScript using flexbox. Since I only have one CardItem, I can't just copy and paste it three times as it would show the same result in each row. Is there a way to achieve this wit ...

The document type is not compatible with the element "BR" in this location; it is assumed that the "LI" start-tag is missing

How can I create a validated list with HTML 4.01 standards? I tried the following code, but it's giving me an error: "document type does not allow element 'BR' here; assuming missing 'LI' start-tag" <tr> <td colspan="2" ...

Best practices for sending variables to an HTML page using nodemailer

I am interested in sending an email with an HTML template that includes dynamic data. For example, I want to include a unique id within a link on the page. Is it possible to insert dynamic data into HTML content when sending emails? If yes, I would apprec ...

What is the best way to extract and analyze CSS code from an HTML page using Java programming language

I'm looking to extract and parse the content of HTML pages using the Jsoup API, which can be found at . However, I've encountered a challenge in extracting CSS that is located in a different folder. How can this be achieved? Currently, my code ...

Effortlessly lower several elements simultaneously with SlideDown

My form div contains multiple inner divs: <div class="form" style="display:none"> For example: <div class="row"> <?php echo $form->labelEx($model,'comment'); ?> <?php echo $form->textField($model,'commen ...

JavaScript does not display checkbox values

I am currently testing whether checkbox values appear on the client side. When I execute the code, the alert is not showing anything. I would greatly appreciate any assistance, thank you. <div> <label name="finishing"class=" ...

The box on my form is leaking my background color outside the 1px border, but only in Internet Explorer

While experimenting with background gradients and borders one day just for the fun of it, I made an interesting observation in Internet Explorer. The issue I encountered was that the background color was overflowing outside the radius border, but this onl ...

Using Vue.js to dynamically populate all dropdown menus with a v-for loop

Getting started with vue.js, I have a task where I need to loop through user data and display it in bootstrap cols. The number of cols grows based on the number of registered users. Each col contains user data along with a select element. These select ele ...

Looking for the answer to utilize selenium for product scraping

I'm currently focused on a personal project involving parsing product names and prices. To achieve this, you can navigate to shoppingSite. After arriving at the site, click the button below the map, then click it again on the right side. Opt for the u ...

Increment the text counter following the uploading of an image file with html format

I have a form in which I am checking the character limit that a user can input into a text field using the 'onkeyup' attribute to update it in real time. Now, I want to achieve a similar function for image uploading. When a user selects an image ...

Styling Based on Conditions in Angular

Exploring the unique function of conditional formatting in Microsoft Excel, where color bars are utilized to represent percentages in comparison to the highest value. Is there a way to replicate this functionality using HTML5 with CSS or JavaScript? Perha ...

Function activation in Element requires a double click to initiate

I've encountered an issue with a web element I'm working on where the click function only triggers after the first click, rendering the initial click ineffective. Here's the code snippet in question: HTML: <div> <a href="#0" cla ...