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

Tips for arranging divs in CSS grid with grid-template-areas technique

I am attempting to organize similar groups of elements in a grid: #grid { position: absolute; left: 135px; top: 158px; width: 1080px; height: 1035px; display: grid; grid-template-rows: 99px 1fr 1fr; grid-template-column ...

How can you override the selected classes for menu items in Material-UI using React.js?

Hey there! I'm facing an issue where I can't override the class that displays the correct styling when a menuItem is selected. Below is my code: <MenuItem component={Link} to="/Acceuil" className={{root:classes.menuItem ,selected:cla ...

What steps do I need to take in order to change an HTML div's background to a black

My current project involves dynamically loading HTML content stored on disk into a specific div element. This is achieved by using the following code: $('#FictionContent').load('Content/HuckFinn.html'); Just to provide some background ...

Relative positioning can break the background-clip attribute for text elements

I am experimenting with using background-clip: text on an element that contains some child <p> elements. I wanted to enhance the design by adding some absolutely positioned :after elements to the <p> tags, covering up the text for animation eff ...

Utilizing $.each to dynamically add data to a jQuery Mobile listview

Trying to implement a data reading mechanism using ajax resulted in unexpected html tag generation for <ul> <li>. The code snippet is as follows: (function( $, undefined ) { $(document).on("pagecreate", ".jqm-demos", function(){ ...

Contrasting results when logging an element in Chrome versus IE

Running the script below in Internet Explorer gives the expected output for console.log(target_el): <div class="hidden"></div> However, when run in Chrome, the output changes to: <div class="visible"></div> To add a humorous twi ...

Tips for sending data to CSS in Angular

I have an Angular application where I need to calculate the width of an element and store it in a variable called finalposition. Then, I want to move this element to the left by (finalposition)px when hovering over it. How can I achieve this styling effect ...

Troubleshooting z-index conflict when using :before pseudo element to emphasize list entries

I am experiencing an issue with highlighting items in a list generated by JSTree using the :before pseudo element. The z-indexes seem to be causing some trouble, as adjusting them results in the highlighting appearing either behind all links or in front of ...

Tips for switching images in a grid using jQuery

I have implemented an image grid using flexbox on a website I am developing. The grid consists of 8 boxes, and my goal is to randomly select one box every 2 seconds and assign it one of 12 random images. My strategy involves creating an array containing UR ...

Control other inputs according to the chosen option

Here is the HTML code snippet: <fieldset> <label for="tipoPre">Select prize type:</label> <select id="tipoPre"><option value="Consumer Refund">Consumer Refund</option> <option value="Accumulated Prize Ref ...

What is the best way to display and conceal various elements with each individual click?

Utilizing the onClick function for each triggering element, I have implemented a show/hide feature for multiple element IDs upon click. The default setting is to hide the show/hide elements using CSS display property, except for the initial 3 main elements ...

Sticky positioning and visible overflow restrictions

When position sticky is used within a container with overflow:hidden, it does not work as expected. However, the overflow hidden property is necessary in this case. <div class="lg:col-start-7 lg:col-end-13" style="overflow:hidden"&g ...

On-page refresh triggering HTTP 404 error in Vue3 routing situation

Issue Upon reloading a route, such as /installer, in Vue3.js, I encounter the following error: Code Snippet I am utilizing the Router with the setup below: const router = createRouter({ history: createWebHistory(process.env.BASE_URL), routes, }); E ...

Encountering a problem with Selenium when dealing with tabular data displayed in a DIV format on a website, where each row is encapsulated within its own DIV element

While creating Selenium automation tests for a website with multiple rows contained within a main DIV element, each row represented by a separate DIV. For example, if there are 5 dynamically generated rows, the HTML code structure would look like this: < ...

Struggling to align a div at the center of a screen

Snippet of HTML Code: <body> <!-- Social Media Icons --> <div id="sm1"><a href="/"><img src="images/facebook.png" height=40 width=40></img></a> </div> <div id="sm2"><a href="/"><img src="image ...

Is there a way to conceal the scrollbar in the mobile view (on a mobile device or emulator) in a React application without disrupting the scrolling functionality?

I am looking to conceal the scrollbar on mobile devices throughout my app while still allowing users to scroll. I have attempted to hide the scrollbar using CSS properties like scrollbar, scrollbar-thumb, scrollbar-thumb:hover, and scrollbar-track. This ...

What is causing my Fabric.js canvas to malfunction?

Here is the link to my JSFiddle project: http://jsfiddle.net/UTf87/ I am facing an issue where the rectangle I intended to display on my canvas is not showing up. Can anyone help me figure out why? HTML: <div id="CanvasContainer"> <canvas id ...

Fixed position scrollable tabs with Material UI

I recently implemented material-ui scrollable tabs in my project, referencing the documentation at https://mui.com/material-ui/react-tabs/#scrollable-tabs. Here is a snippet of the code I used: <Tabs value={value} onChange={handleChange ...

How can you dynamically disable the submit button on a form in Angular 7+ based on the form's current status?

Let's consider a scenario with a button in our code: <button type="button" class="menu-button" [disabled]="isInvalidForm()">Save</button isInvalidForm() { console.log('I am running!'); return this.nameValidator.errors || this.last ...

Sleek and versatile sidebar reaching full height

Is there a way to make my sidebar cover the full height of the screen without using position: fixed? The code I've tried doesn't seem quite right. Any tips? JSFindle: http://jsfiddle.net/Pw4FN/57/ if($(window).height() > $('#page-contai ...