Difficulties encountered while trying to set up a multi-level list for a mobile

Trying out a tutorial to create a mobile dropdown menu.

Encountering an issue when adding new lists inside a previous tag affects the functionality of the dropdown menu. Attempted to adjust the CSS without success.

All the lists are displayed without requiring user interaction when adding a new multi list to the previous tag.

<nav id="nav" role="navigation">
<a href="#nav">Show navigation</a>
<a href="#">Hide navigation</a>
<ul class="clearfix">
    <li class="active"><a href="?home">Home</a></li>
    <li>
        <a href="?blog" aria-haspopup="true"><span>Blog</span></a>
        <ul>
            <li><a href="?javascript">JavaScript</a></li>
            <li>
                <a href="?blog" aria-haspopup="true"><span>Test</span></a>
                <ul>
                <li><a href="?design">One</a></li>
                </ul>
            </li>
        </ul>
    </li>
    <li>
        <a href="?work" aria-haspopup="true"><span>Work</span></a>
        <ul>
            <li><a href="?webdesign">Web Design</a></li>
        </ul>
    </li>
    <li><a href="?about">About</a></li>
</ul>

Not including the entire code due to numerous CSS elements. Please refer to the sample code below for reference.

Check out this working example.

https://jsfiddle.net/cys670Lh/1/

Answer №1

For a more precise approach, consider utilizing the > selector when hovering to target only the immediate child rather than all descendants. Then, incorporate a new hover rule for the subsequent submenu...

 #nav > ul > li:hover > ul
    {
        display: block;
        left: 0;
        right: 0;
    }
#nav > ul > li > ul > li:hover ul
    {
        display: block;
        left: 0;
        right: 0;
    }

FIDDLE

On another note, I recommend avoiding using hover to reveal menu subcategories, especially on mobile devices. It may be more effective to implement an event on click with JavaScript instead.

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

Interactive website information

Currently, my website features a jQuery UI navigation system and utilizes ajax to dynamically update content by swapping div ids from one html file to another. However, this method still involves multiple HTML files which can become cumbersome. I am curiou ...

Utilizing headless WordPress and React for an innovative web development approach, incorporating styles seamlessly in both the

I am looking to create a headless WordPress + React website. So far, I have successfully set up the "non-gutenberg" elements like the header and footer. Everything seems to be working fine on that front. However, I am facing an issue with the styling of t ...

The error message being thrown is: "Cannot access the 'top' property of an undefined value with the offset().top-500 method."

As a beginner in testing, I encountered a console error on my page while scrolling. The error message displayed was: main.js:18 Uncaught TypeError: Cannot read property 'top' of undefined at main.js:18 at dispatch (jquery-1.9.js:3) at v.han ...

Ways to activate a hover effect on an external element

Hello everyone! This is my first time posting here and I've been struggling to find a solution with my limited knowledge. I could really use some help on this: Is there a way to trigger a hover effect on an element that is not related (no parent, ch ...

Encountering numerous challenges while attempting to create a switch theme button with the help of JavaScript's localStorage and CSS variables

It's frustrating that despite all my efforts, I'm still stuck on implementing a small feature for the past 5-6 hours. I need assistance with storing a single variable in the user's localStorage, initially set to 1. When the user clicks a but ...

Using select tags in conjunction with JavaScript can add dynamic functionality to your website

I've been working on adding dropdown menus to my website and have been using code similar to this: <select> <option value="volvo">Volvo</option> <option value="saab">Saab</option> <option value="opel">Opel</opti ...

Using jQuery to select ASP control based on its dynamically generated Name attribute

When attempting to reference an ASP control in JavaScript, I initially used the generated ID but encountered issues. Surprisingly, referencing the control by its generated "Name" proved to be successful. ASP <asp:CheckBox ID="chkMyself" runat="server" ...

Display different data in an HTML table for each individual click on the "Read more" event

I am currently extracting data from a SQL table to exhibit it in an HTML table. The issue I am facing is that I would like to implement a "Read More" feature to prevent clutter in the table. As I am retrieving the data row by row, I am utilizing a class n ...

Adding or changing class in Angular 2 based on specific conditions

Currently, my focus is on building a web application using Angular and the Semantic-UI framework. In order to add a single class to an element based on a specific condition, I have successfully implemented the following syntax: [class.className]='co ...

Why is the hashtag (#) mysteriously vanishing from the URL?

Imagine a scenario where you have a page with a URL like mypage.php#tab3, and there is a link that looks like this: When you click on the "Add" link, the URL becomes shorter to just mypage.php#. The code for the "Add" function is as follows: function ad ...

What are the steps to disable CSS in order to speed up the execution of automation tests?

Source: What is the optimal method to temporarily disable CSS transition effects? When testing JavaScript, I typically utilize JavascriptExecutor, however, none of the aforementioned blogs shed light on how this can be achieved. I attempted: js.execu ...

What is the best method for retrieving text from elements designated by class?

I am currently using BeautifulSoup to scrape data from a website, but I am facing an issue with extracting only the text I need. The specific part of the website data that I want to grab is: <div content-43 class="item-name">This is the te ...

Is there a way to adjust the speed of the transitions between animations?

I've been experimenting with ways to increase the time between animations in my cycle. Adjusting the duration of the keyframes animation hasn't yielded the desired effect. span { animation: rotateWordsFirst 15s linear infinite 0s; ...

Step by step guide on incorporating two background images in a single header

I'm looking to create a header with a background image that appears twice, like this: To achieve the effect, I added opacity of 0.5 to one of the images, but it is affecting everything in my header including text and logo. Is there a way to prevent t ...

Facebook is failing to detect any meta tags in the header of my React web application

After checking my code on https://validator.w3.org/, everything seems fine. However, I noticed that Facebook is not reading most of the content from the head section - not even a single meta tag. On the other hand, Google is able to read all the content fr ...

Unable to conceal the scrollbar while keeping the div scrollable

I've been attempting to implement the techniques outlined in the guides on this site, but I'm encountering difficulty hiding the scroll bar while still maintaining scrolling functionality! My current approach involves setting the parent as relat ...

Content loading problem tied to History API

Recently, I started exploring the concept of loading content asynchronously using HTML5's History API. However, I've encountered a challenge where the loadContent() method gets called multiple times when a <a href> is clicked, especially w ...

Adjust the height of videos automatically on columns

I need help figuring out how to display two videos with different dimensions side by side without any weird gaps. I've already tried using flex display with no luck. My current code looks like this: <div class="row"> <d ...

Using the paragraph element within a flexbox forces the parent element to expand to the full width

I am attempting to design a straightforward layout where a heading, paragraph, and button are centered both horizontally and vertically on the page. My goal is for the .centered-div to match the width of the .heading. The issue arises when the paragraph t ...

How can elements be concealed in HTML using CSS if they do not have an ID or class?

Looking for a way to hide the second span element within a div that does not have an ID, but its parent div does. The goal is to target and hide the span that contains "second". <div id="example"> <div> <span>First</span> ...