The CSS affecting the dropdown box on the HTML page is causing it to malfunction

Whenever I hover over the main menu ("for example: Menu 2"), I am able to see the dropdown list underneath.

However, when I try to move my cursor to submenu1, it does not display and I cannot select it either.

Below is a snippet of my code for reference:

<style type="text/css">

ul#menu, ul#menu ul.sub-menu {
    padding:0;
    margin: 0;
}
ul#menu li, ul#menu ul.sub-menu li {
    list-style-type: none;
    display: inline-block;
}
/*Link Appearance*/
ul#menu li a, ul#menu li ul.sub-menu li a {
    text-decoration: none;
    color: #fff;
    background: #666;
    padding: 5px;
    display:inline-block;
}
/*Make the parent of sub-menu relative*/
ul#menu li {
    position: relative;
}
/*sub menu*/
ul#menu li ul.sub-menu {
    display:none;
    position: absolute;
    top: 30px;
    left: 0;
    width: 100px;
}
ul#menu li:hover ul.sub-menu {
    display:block;
}

</style>

<div id="menu" align="left">

<ul id="menu">
    <li>
        <a href='<%=request.getContextPath()%>/auth/gs.page'>Menu1</a>
    </li>
    <li><a>Menu2</a>

        <ul class="sub-menu">
            <li>
                <a href='<%=request.getContextPath()%>/auth/view.page'>submenu1</a>
            </li>
        </ul>
    </li>

</div>

I would appreciate any suggestions or solutions to fix this issue.

Answer №1

It seems like the issue you're observing is the submenu disappearing when you move your mouse downward from the main navigation item.

This happens because there is a small gap (around 1-3px depending on the browser and default user styles) that causes the submenu to lose its 'hover' status, leading it to hide as you "unhover" the top-level nav item while crossing over that gap.

If this is indeed the problem, the simplest solution would be to eliminate the 'top' value from 'ul#menu li ul.sub-menu' (which is currently set to '30px') and instead add equivalent padding to the 'li' element of the submenu for the correct visual appearance.

ul#menu li ul.sub-menu {
    display:none;
    position: absolute;
    left: 0;
    width: 100px;
}


ul#menu li ul.sub-menu li {
     padding-top: 2px;   
}

You can view the updated version with these changes on this fiddle: http://jsfiddle.net/adnrw/J44NJ/

Answer №2

Upon reviewing your code, I did not encounter any issues. Can you please provide more details on what you mean by "not displaying immediately"?

Answer №3

ul#menu li:hover ul.sub-menu

It might be more useful as:

ul#menu li:hover ul.sub-menu, ul#menu li ul.sub-menu:hover

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

Cordova Geolocation now displaying incorrect latitude and longitude values as NAN

Recently starting out with javascript and Cordova, I decided to develop a basic GPS app in Visual Studio 2015. The goal was simple: get my current position by clicking on the "CURRENT POSITION" button. Testing it in Firefox yielded positive results. Howev ...

Emphasize a portion of a text / Apply formatting to a variable

I am facing an issue where I need to format only the date in a specific string. I have managed to extract the date and store it in a variable after isolating it from the original message. <div class="foo"><p> Click here now and get by January ...

How can I save or export an image file containing HTML content?

Currently, I am working on a project where I am generating dynamic HTML content. My goal is to be able to export or save this HTML content as an image file using PHP, jQuery, and JavaScript (or any other method if applicable). Can anyone help with the im ...

Overlap and cover additional elements within a DIV

I am looking to create a versatile function that can effortlessly overlay various elements such as selects, textfields, inputs, divs, tables, and more with a partially transparent div matching their exact height and width. I have managed to obtain the pos ...

What techniques can be applied to keep a flexbox from expanding in width when it includes a text input field?

After implementing the following CSS/HTML code, I achieved my desired outcome - three boxes displayed in a row. The middle box has a fixed width while the outer boxes expand equally on either side: #container { display: flex; } #container > * { back ...

Bizarre display of miscellaneous items on the monitor

Hey there, I've been working on creating a div to display information about both the Civilian and Vehicle that users input. Initially, everything worked perfectly with my HTML and CSS until I introduced two additional divs into the layout. With just o ...

Is there a way to determine the bounding rectangle of a specific word within a paragraph when you only have its index?

I am currently developing a text-to-speech functionality for a react application that can emphasize the word being spoken by highlighting it with a background color. This feature closely resembles the layout of the Firefox reader view. However, my curren ...

Tips for Controlling an Absent Search Bar in the HTML Source Code with Selenium

I'm attempting to automate searches using Selenium in Java. Upon inspecting the search bar on the page, I noticed that it has an id of searchBox and a name of q, which could be helpful. However, these properties are not visible in the HTML when viewi ...

"Radio button is set as default option, however the dropdown menu is not displaying

I am experiencing an issue with a credit card payment form on my website. Unlike similar websites where the dropdown list of credit cards automatically displays when the page loads, on this site the list does not show until a second click occurs on the alr ...

Jquery Position behaving unexpectedly during initial invocation

My goal is to have the autocomplete menu open above the input box if there is not enough space below it. The code functions properly, except for the initial render. It consistently displays at the bottom in the following scenarios: 1. When starting a searc ...

What is the process for converting plain text into an image tag using the methods ".replace()" and ".html()"?

My goal is to customize this particular answer so that it can transform classic BCCode [img]{url}[/img] into an HTML image. In the code snippet provided, I have successfully implemented something similar with [b]text[/b]. However, when attempting to use [i ...

The HTML element seems to be missing its height parameter

My element doesn't have a set height, but it's populated with images causing the Anchor around the images to be unclickable unless I assign a fixed height to .portfolio. Any ideas on how to resolve this? HTML Snippet : <h1 class="text-c ...

Confusion arises when using Materialize CSS for selecting elements

Currently, I am working on an app using Cordova. Within this project, I have incorporated jQuery Mobile's CSS and JS along with Materialize CSS and JS. However, I recently encountered an issue after integrating the Materialize files. Specifically, whe ...

tips for extracting live hyperlinks by accessing hrefs

While parsing the HTML code of a webpage, I am extracting all the links mentioned as hrefs using regex. However, I have encountered a situation where certain websites, like Wikipedia, mention hrefs in the HTML code as a paraphrase. For example: The code s ...

The table does not move up or down when using the mousewheel over the rows, but only when

I'm encountering an issue with a table inside a div that has overflow-y: scroll applied to it. While the scrollbar appears when there is content overflow, I am unable to scroll using the scrollwheel. It only works when the cursor is directly on top o ...

Activate mouse event when the pointer is within X units of the bottom of the browser window

My inquiry is straightforward, although the solution may not be as simple. I have an element fixed to the bottom of the browser window. When it is not needed, I want to hide it by setting its height to 0px. Whenever the user's mouse is a certain dista ...

Transform the Bootstrap container to fill the entire height of the browser

How can I make the container height 100% of the browser without breaking the contents inside? html, body { height: 100%; min-height: 100%; } .container { min-height: 100%; height: 100%; background-color:red; } <div class="contai ...

Information displayed when Tab is inactive - Material Ui and React

Just diving into the world of React and UI design, seeking some guidance on an issue I'm facing. I'm working on implementing Material Ui Tabs in my Component, but struggling to get a tooltip to show on a disabled Tab. Here's a snippet of my ...

Tips for consistently positioning a div beneath another div in HTML/CSS

Would appreciate it if you could review this. <.div id="main"> Main Div <./div> <br/> <.div id="sub">Sub-Division<./div> ...

Troubleshooting: Bootstrap 5.0 Navbar Dropdown Issue Unresolved

My navbar dropdown isn't working when clicked. I've searched for solutions without success. Is there a script missing? layout.html: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> ...