How can the top level menu remain in hover state while navigating to sub menus?

I need help with creating a horizontal menu that has 2 sublevels. I want to keep the top-level menu in hover state when moving down. Here is the HTML and CSS code:

For the HTML Code:

<div>
    <ul id="nav">
        <li><a href="#">Home</a></li>
        <li><a href="#">Products</a>
            <ul class="child">
                <li><a href="#">Hard Drives</a></li>
                <li><a href="#">Monitors</a></li>
                <li><a href="#">Speakers</a>
                    <ul class="child">
                        <li><a href="#">10 watt</a></li>
                        <li><a href="#">20 watt</a></li>
                        <li><a href="#">30 watt</a></li>
                    </ul>
                </li>
                <li><a href="#">Random Equipment</a></li>
            </ul>
        </li>
        <li><a href="#">Services</a>
            <ul class="child">
                <li><a href="#">Repairs</a></li>
                <li><a href="#">Installations</a></li>
                <li><a href="#">Setups</a></li>
            </ul>
        </li>
        <li><a href="#">About</a></li>
        <li><a href="#">Contact</a></li>
    </ul>
</div>

And for the CSS Code:

> body {
}
#nav li {
    list-style:none;
    float: left;
}
#nav li a {
    display: block;
    padding: 8px 12px;
    text-decoration: none;
}

/* Additional CSS code goes here */

If anybody could provide guidance on how to achieve this, it would be much appreciated. Thank you.

Answer №1

Update the selector as follows:

#nav > li:hover > a

Instead of

#nav > li > a:hover

Also change

#nav li ul li:hover > a

from

#nav li ul li a: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

Do mouse users prefer larger buttons on RWD sites for a better experience?

Not entirely certain if this platform is the most suitable for posing this query, so if warranted, please close it and recommend a more appropriate venue for such inquiries. In the realm of responsive web design (RWD) today, it is common practice for webs ...

What strategies should be employed to manage data-driven input in this particular scenario?

In the process of creating a small webpage, I have designed 2 navigation panels - one on the left and one on the right. The leftNav panel contains a list of different flower names. While the rightNav panel displays images corresponding to each flower. A ...

Creating margins between columns in Bootstrap can easily be accomplished by adjusting the padding or gutter settings

For my Bootstrap page, I'm trying to create 4 columns with a space of 5px between each one. I found a tutorial ( ) but it's not working as expected because the clickable area extends beyond the column due to the margin. Here is the link to my j ...

Creating a right triangle with a background filled with linear gradients: tips and tricks

Looking to create a right triangle with a linear-gradient background color in CSS? Wondering if it's possible? Check out the code I currently have for a right triangle with a single background color. You can also find the same code here. <style&g ...

Strategies for Resolving the IE 8 Issue with Table Row Background Images

Looking for some assistance with this issue. The solution I found doesn't seem to be working properly in IE 8. In short, when you add a background image to a table row, the background is showing up in all the inner cells as well. ...

What is causing the col-auto with the red border to exceed its available height?

For this code, I've utilized version 5 of Bootstrap. In full screen width, the col-auto with the red border seems to be taking up more space than its content. The yellow border marks the available content space inside. I'm curious about what migh ...

The overlay background on the image does not seem to be functioning correctly

I'm currently working on adding an overlay to my image in order to darken it and display text over the top. I've tried using absolute positioning for both the image and overlay, but the overlay ends up covering the entire window and sitting above ...

Unleashing the Power of Tailwind CSS: Enabling Group Hover Effects on Anchor Tags

When I run my code on play.tailwindcss.com, the group hover feature works fine. However, when I copy the same code into my local file, the group hover doesn't work there. What do I need to add to my tailwind.config.css file in order to enable group ...

Page positioned absolutely with a sticky footer

Introducing myself to those familiar with my previous query on the topic of Stick Footer (not sticking!), I am in search of guidance once again. Special thanks to Andres Ilich for shedding light on why my footer failed to adhere to the bottom of the page - ...

The back-to-top feature is malfunctioning in the new Bootstrap 4 update

I've been working on adding a back-to-top button to my website using JavaScript in Bootstrap 4 with the Font Awesome icon set. It was functioning perfectly until I made some changes to the site, and now it's not working anymore. I'm pretty n ...

How to add a background image to a submit button in Symfony

Is it possible to customize the submit button in my search form to display a background image of a search icon instead of just text that reads 'Search'? Currently, my form setup in the controller looks like this: $form = $this->get('form ...

Utilizing D3 for embedding a background image in an SVG

After exploring different options, I have decided to switch from my previous Bootstrap framework to using a solid SVG strip with D3 for my project. The objective is to create 3 clickable triangles that will mask images and act as anchor links within the s ...

Obtaining the actual dimensions of an image

I am trying to retrieve the original height and width of an image stored in a variable called var IMG = $("img"). The code I have written functions correctly except when used on Win XP IE8. Can someone help me troubleshoot this issue? $("<img/>") ...

My goal is to align my navigation bar in the center of the page, ensuring there is a 5-pixel margin on each side of the bar without adjusting the position of any of the tabs

ul { list-style-type: none; margin: 0; padding: 0; overflow: hidden; background-color: black; position: absolute; } li { float: left; border-right: 1px solid #bbb; } li a { display: block; color: white; text-align: center; padding ...

Custom font causing vertical gaps in masonry grid layout plugin

My front page layout is arranged using the "Masonry" jQuery plugin, with each div containing an upper image div and a lower text div. The plugin is initialized like this: function use_masonry() { var container = document.querySelector( ...

Guide to setting up a horizontal button menu and dropdown submenu beneath the navigation bar using Bootstrap 4

How can I design a horizontal button menu with submenus below the navigation bar in Bootstrap 4? Take a look at the image below to see what I'm aiming for: https://i.sstatic.net/j6b8a.png https://i.sstatic.net/rmtrM.png If you have any ideas or su ...

Refinement of website footer alignment

As a web designer, I am experiencing difficulty in adjusting the footer on my website. I would like the footer to be fixed at a specific height and remain in the same position unless the content increases, in which case it should move down accordingly. Can ...

Is it possible to make the `<body>` element respect the offset (i.e. the user's current scroll position) when the 'custombox' modal is triggered?

I'm currently facing an issue with the scroll bars in the browser while using custombox.js in combination with BS4. Let me provide some context: I am working with a Custombox modal, which is similar to a BS4 modal. When a modal is opened in BS4, a c ...

Stylish CSS: Jagged 3-dimensional rotated text

Have a look at this Codepen to see the issue. As the text moves into the background, more aliasing appears. A screenshot taken in Chrome on macOS (similar appearance in FF & Safari): https://i.sstatic.net/n746I.png I've experimented with different ...

The global CSS header element in Next.js is not being applied to parsed markdown files; instead, it is being replaced by Tailwind CSS

After attempting to convert Markdown into HTML, I encountered an issue. While the markdown parsed correctly, the rendered output did not match my expectations. Specifically, I expected the headers to automatically appear bold and with a larger font size, b ...