When hovering over the submenu, it disappears

I am currently experiencing an issue with my submenu disappearing when I move the mouse out of the a-element. As a new student in web development, I have spent hours searching on Google for solutions but haven't been able to resolve it.

One solution I tried was using .topbar #menus li:hover + .sub, however, this caused the submenu to not show up at all.

I would greatly appreciate any help or suggestions regarding this problem.

.topbar #menus{
    position: absolute;
    display: flex;
    flex-flow: row;
    justify-content: space-around;
}

.topbar #menus > li{
    border: 2px solid rgb(20, 20, 20);
    
}

.topbar #menus li a{
    display: inline-block;
    width: 100%;
    height: 100%;
    margin-bottom: 0;
}

.sub a{
    display: inline-block;
    width: 100%;
    height: 100%;
}

.sub{
    display: none;
    border: 2px solid black;
}

.topbar #menus li a:hover + .sub{
    display: block;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <link rel="stylesheet" href="style.css">
    <title>Element</title>
</head>
<body>
    <div class="topbar">
        <ul id="menus">
            <li id="food"><a href="food.html">FOOD</a>
                <ul class="sub">
                    <li id="breakfast"><a href="#">BREAKFAST</a></li>
                </ul>
            </li>
            <li id="drinks"><a href="drinks.html">DRINKS</a>
                <ul class="sub">
                    <li id="colddrinks"><a href="#">COLD DRINKS</a></li>
                </ul>
            </li>
            <li id="offers"><a href="offers.html">OFFERS</a>
                <ul class="sub">
                    <li id="foodoffers"><a href="#">FOOD OFFERS</a></li>
                </ul>
            </li>
        </ul>
        
    </div>
</body>
</html>

Answer №1

Greetings!

  .topbar #menus li:hover .sub{
    display: block;
}

This is the modified line! Best of luck!

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

How to Position Icon on the Right Side of an Input Field using CSS

Is there a way to position the magnifying glass icon to the right side of my input field? Link to my Fiddle. @import url("//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css"); body { margin: 30px; } .search { position: relative; ...

Incorporate AJAX functionality with a simple HTML button

Upon clicking the button, the AJAX call fails to execute. Below is the HTML code for the buttons: <td><button id=${data[i].id} name="update" type="button" value="${data[i].id}" class="btn btn-primary update" ...

Ways to increase the font size of input text using bootstrap's css framework

I currently have a bootstrap textbox set up like this: <input type="text" class="span9" required name="input_text"/> My goal is to increase the height of my input box to 300px. The width, on the other hand, is being handled by span9. I utilized In ...

Tips for stopping a browser from automatically opening a new page when a form is submitted

On a webpage, there is a form for email subscription. When a user enters their email and clicks the submit button, we do not want the page to redirect to a specific URL. Instead, we simply want the text value of the submit button to change to something lik ...

Managing special characters in PHP: Understanding charsets

While working on my website using HTML and PHP, I am having an issue with special characters (Å, Á ...) appearing as on the screen when using the post function. Strangely enough, all other HTML content displays correctly. Any suggestions for a solution ...

Modify the color of a set of div elements when clicked

Is there a way to change the background color of all divs with a common attribute value (#id for example) after clicking on one of the divs that shares the same attribute value? This is what I have tried so far: $('.group').click(function(){ ...

Tips for showing a message in the modal after a user completes the registration process

This code snippet contains an HTML form for user registration. Upon clicking the register button, users are redirected to another page. However, the desired outcome is to display the message on the same modal form. <div class="popup"> ...

Is there a way to adjust the jQuery cycle plugin to create a slideshow with two images instead of just one?

Picture a slideshow that resembles the one showcased in this link: http://malsup.com/jquery/cycle/div.html, but with only two images instead of three. Also envision it having two triggers, similar to the demo in the center of this page: http://jquery.mals ...

What methods are available for utilizing DOMStringMap within TypeScript?

Imagine I have this function: angular.forEach(myElements, function prepareElements(myEl: HTMLElement, index) { myEl.dataset.myProperty = "whatever"; }) However, I encounter an issue with error TS2094: The property 'myProperty' does not exi ...

Adding hue to the portion of text following a JavaScript split() operation

I need assistance in printing the text entered in a textarea with different colors. I am separating the string using the split() method, which works fine. However, I now want to print the substrings in the textarea with colors. How can this be achieved? & ...

PHP not displaying Bootstrap input validation message set by JS

Currently, I am attempting to implement error messages using .setCustomValidity() and the .invalid-feedback class on an HTML form utilizing Bootstrap 4. Essentially, when the user validates the form, a JavaScript script assesses the inputs and if any erro ...

Is there a way to implement CSS transitions when hiding elements?

My bootstrap navbar collapses and displays items outside of it. However, when I hide the menu, the overlay div disappears immediately and does not transition smoothly with the menu. How can I apply a transition to the div when hiding the menu? I've t ...

Adjust the size of the div menu according to the window's dimensions

Is there a way to make a menu that will resize both the width and height of the window? I've managed to resize the width using %, but for some reason, the height isn't cooperating. I've experimented with max-width/height settings and tried ...

I find myself struggling to manage my javascript dependencies

Currently, I am utilizing NPM along with various angular packages. As per the tutorial on Basic Grid Part 1 at this link, I am encountering challenges. This is my file directory structure: D:/nodeStuff/uiGrid includes: node_modules uigrid.css uigrid.h ...

Dynamic Data Display

I'm experiencing an issue where the data is not displaying in the table div when using an Ajax call to load the table. The page appears blank upon return, and I have tried using $('#groupTable').load(data); without any success. If anyone can ...

Using JavaScript to conceal the browser's interface leads to a flaw with the position: fixed property specifically

Check out my website: On this site, there is a fixed position div #nav. In order to optimize the site for mobile, I am using JavaScript to hide the browser's chrome. Here's the code snippet: setTimeout(function() { window.scrollTo(0, 1) }, 10 ...

Issues with Firefox's flexbox functionality are preventing it from working

Hey there, I've created a bubble menu with a button using code. It functions perfectly on Chrome but seems to have some issues on Mozilla Firefox. You can check it out and give it a try. $(".roundedBallOuter").click(function(e) { $(this).toggleCl ...

Immediate family members nearby are not an option. We will have to create the form dynamically

On a previous page, there is a form that allows users to input data and define the number of "Attributes" they want to assign to a device by clicking on a button. Users are prompted to specify a name and type for each attribute. If the user selects "Selec ...

In HTML, utilize the "clone" div class

Upon inspecting the element of my website, I have observed that the top-header div contains a duplicate. Why did this occur? How can I eliminate the clone and retain the original div top-header? Visit my site Below is the HTML code: <div id="top-h ...

Is it possible to embed HTML within standard PHP without using alternative methods?

Is it possible to embed HTML inside a PHP "if" statement? The top-rated answer in this thread on Stack Overflow discusses using alternative if style. While other answers suggest that it also works with normal if statements, the question remains: is this a ...