Troubleshooting: Submenu vanishes when hovering over CSS/HTML menu

Having difficulty getting the hover menu to function correctly. When hovering over the main menu item in the link below, the submenu appears but disappears when attempting to hover over it.

Check out this Fiddle

HTML Code

<div id='menu'>
    <ul>
        <li>
            <center><a href="#">Services</a>
            </center>
            <ul>
                <li><a href="#">Moving help ~ Deliveries</a>
                </li>
                <li><a href="#">Around the property</a>
                </li>
                <li> <a href="#"> Cleaning</a>
                </li>
                <li> <a href="#"> Minor Home Repairs</a> 
                </li>
                <li><a href="#"> Personal Care</a> 
                </li>
                <li><a href="#"> Skiller Handyperson</a>
                </li>
            </ul>
        </li>
        <li>
            <center> <a href='#'>company</a>
            </center>
            <ul>
                <li> <a href="about.php" class="firstli">About us </a>
                </li>
                <li> <a href="contact.php">Contact us </a>
                </li>
                <li> <a href="faq.php">F.A.Q. </a>
                </li>
                <li><a href="term.php">Terms of Use </a>
                </li>
                <li><a href="privacy.php" style="border-right:0px;">Privacy Policy </a>
                </li>
            </ul>
        </li>
    </ul>
</div>
</div>

CSS Styling

#menu * {
    padding:0;
    margin: 0;
    font: 12px georgia;
    list-style-type:none;
}
#menu {
    margin-top:300px;
    background-color:none;
    float: left;
    line-height: 10px;
}
#menu a {
    display: block;
    text-decoration: none;
}
#menu a:hover {
}
#menu ul li ul li a:hover {
    padding-left:9px;
    border-left: solid 1px #000;
}
#menu ul {
    margin-bottom:10px;
}
#menu ul li ul li {
    width: 140px;
    border: none;
    color: #eee;
    padding-top: 3px;
    padding-bottom:3px;
    padding-left: 3px;
    padding-right: 3px;
    background:black;
}
#menu ul li ul li a {
    font: 11px arial;
    font-weight:normal;
    font-variant: small-caps;
    padding-top:3px;
    padding-bottom:3px;
}
#menu ul li {
    float: left;
    width: 146px;
    font-weight: bold;
    border-top: solid 1px #283923;
    border-bottom: solid 1px #283923;
}
#menu ul li a {
    padding-left: 15px padding-right: 10px;
}
#menu li {
    position:relative;
    float:left;
}
#menu ul li ul, #menu:hover ul li ul, #menu:hover ul li:hover ul li ul {
    display:none;
    list-style-type:none;
    width: 140px;
}
#menu:hover ul, #menu:hover ul li:hover ul, #menu:hover ul li:hover ul li:hover ul {
    display:block;
}
#menu:hover ul li:hover ul li:hover ul {
    position: absolute;
    margin-top: -22px;
    font: 10px;
}
#menu:hover ul li:hover ul {
    position: absolute;
    margin-top: 1px;
    font: 10px;
    bottom:100%;
}

Answer №1

There seems to be an issue with the inner list having a bottom margin, causing it to be separated from the parent li element:

To maintain the spacing while resolving this problem, you can apply the following CSS:

#menu ul {
    padding-bottom: 20px;
    margin-bottom: 0;
}

Check out the updated example on JSFiddle

By implementing this solution, the gap between elements is eliminated, and the :hover state is preserved.

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

Special Table Spacing

Within my table, I am looking to create spacing between cells without setting padding and/or margin on each individual td. While using the CellSpacing and/or CellPadding properties of the table could be a potential solution, these properties apply space on ...

Cookie does not store the username and password

When I click on the "Remember Me" checkbox, I want to set the username and password and destroy the cookie when unchecked. However, when I check the output of the cookie, nothing is set. I would like to share my code for review to help me identify where I ...

Is there a function called 'onViewportChange' in media queries that triggers a search in the .css file for applicable styling?

So I'm not entirely sure about all the specifics, but my understanding is that each time a new HTML element is created, it checks through all linked CSS files and inline styles to see if those styles should be applied to that element. This suggests t ...

Connect the checkbox input to the text input

I'm facing an issue where I need to tie a checkbox input to a text input in my form. Here's the scenario: I am extracting data from a database. The primary key data serves as the value for the checkboxes. When a checkbox is selected, it should ...

Adjusting the margins of jQuery mobile buttons

I seem to be stuck on a simple error that is causing me to spin my wheels. Take a look at the following jqm (version 1.3) view (in haml) #main-header{'data-role' => 'header'} #main-content{'data-role' => 'content ...

Is there a way to create a dropdown menu that transforms into a burger icon on smaller screens, while still housing all of my navigation items within it?

I'm currently working on a segment of my header that includes a navbar with 3 links, as well as a dropdown menu listing additional functionalities. Here is the current code I have: <div class="col-md-4 pt-4"> <nav class="navbar ...

Align a span vertically within a div

I need help aligning the content "ABC Company" vertically within a div using Bootstrap 4's alignment helper classes. Despite my efforts, I have not been successful. Here is the code I am using: <div class="container" style="width: 740px;"> < ...

unable to modify the content within a div by clicking on a link

Lately, I've been experimenting with a code snippet I found on this fiddle: http://jsfiddle.net/unbornink/LUKGt/. The goal is to change the content of a div when clicking on links to see if it will work on my website. However, no matter which link I c ...

What is the best way to insert a line break following a font awesome icon within a list?

My goal is to design a menu similar to LinkedIn's, featuring buttons made from icons positioned above text. However, I'm facing difficulty in inserting line breaks in CSS format after my FontAwesome icons. Despite having 'display:block' ...

Progress bar for uploading files

Similar Question: Upload Progress Bar in PHP Looking for suggestions on a simple and effective method to implement a file upload progress bar. Interested in a solution that involves both javascript and php. Any recommendations? ...

Tips for abbreviating HTML content using PHP

Similar Question: PHP: Truncate HTML, ignoring tags I have some HTML content stored in a database. I need to display this content in a shortened form. I attempted to use the mb_strstr function like so; $str = mb_strstr($this->htmlData, "</p> ...

Is there a way to showcase the present weather conditions using simpleweather.js in plain text format?

I have integrated the weather.js library into my HTML file by adding the necessary imports: <script src="js/current.js"></script> <script src="js/sugar.min.js"></script> <script src="js/weather.js"></script> <script ...

Is it possible to customize the appearance of password fields with reduced dot size in Safari on iOS 12?

Has anyone experienced the issue of iOS 12 Safari displaying huge dots in the password input field? I'm looking for a way to make them look like they do in Chrome. Is there a known method to customize the style of these inputs using CSS? <input ty ...

Having trouble with Safari on your iPhone? Seeing image outlines peeking through radius borders?

Has anyone encountered a similar issue before? I'm experiencing this problem specifically on Safari for iPhone. Problem: https://i.sstatic.net/ffqWz.jpg Solution: https://i.sstatic.net/z1bUB.png Below is the HTML code snippet: <div class="row"& ...

When using Selenium to locate a sub element within a previously obtained WebElement using xpath, it will always return the first match found on the entire

Currently, my project involves using selenium and python to automate website testing. I am facing an issue while trying to extract links to files on the website using the following approach: I first use divs = find_elements_by_css_selector("div.answer") to ...

Is it possible to have multiple forms on a master page?

Regarding the limitation of having only 1 runat="server" and <form> per master page, I am facing a dilemma with placing my login form on my website. Should I include it all on the master page or distribute some elements to the .aspx form? Currently, ...

Block elements such as divs are displayed first before inline elements on a webpage

I have multiple child divs inside a parent div. I want the child divs to stack vertically (block) within the height of the parent div, but if they exceed the height, I want them to align horizontally (inline). I have provided an image and included my code ...

Identify Pressed Shift Key Direction - Leveraging JQuery

I am currently working on a web application that requires users to enter capital letters. However, I want to restrict them from using the right shift key for certain keys like a, s, d, f and the left shift key for h, j, k, l in order to detect whether they ...

Ensuring the Selection with jQuery

I've successfully implemented jQuery validation on a text field, but when I try to apply it to a radio button, it doesn't seem to work. I'm not sure what I'm doing wrong. Here is my HTML and jQuery code: <input type="text" placehol ...

Is it possible to insert an image directly into the <img> tag without having to first send it to the server?

I've created an upload form that allows users to submit images: <form> <input accept="image/jpeg, image/gif, image/png" type="file" name="image" id="image" class="UploadInput" onchange="submitImageUploaderForm()"/> </form> Once t ...