I can't seem to get the dropdown list to appear. What could be the issue?

I'm currently trying to create a pure CSS dropdown menu on hover by following this tutorial. However, despite multiple attempts, I'm still stuck and in need of some clear explanations for my issue.

            <div class="navbar">
                <ul>
                    <li>
                    <div><a href="3d.html">3D Printing</a></div>
                        <ul>
                            <li>
                            <div><a href="#">blah</a></div>
                            </li><li>
                            <div><a href="#">blah</a></div>
                            </li><li>
                            <div><a href="#">blah</a></div>
                            </li>
                        </ul>
                    <li>
                    <div><a href="#"></a></div>
                    </li><li>
                    <a href="#"></a>
                    </li>
                </ul>
            </div>

So far, the HTML code seems fine to me.

    .navbar ul {
    position: relative;
    display: inline-block;
    font-family: lemon;
    list-style: none;
    padding: 15px 0px;
    font-size: 210%;
    margin-left: 3%;
    }
    
    .navbar ul:after {
    content: "";
    clear: both;
    display: block;
    }
    
    .navbar ul li {
    display: block;
    }
    
    .navbar ul ul {
    display: none;
    font-size: 100%;
    padding: 18px 5px;
    }
    
    navbar ul li:hover ul  {
    display: block;
    }
    
    .navbar ul ul li {
    background: rgba(0,0,0,0.3);
    border-bottom: 1px solid rgba(0,0,0,0.05);
    }
    
    .navbar ul ul li:hover {
    background: rgba(0,0,0,0.4)
    }
    
    .navbar ul li a {
    display: block;
    text-decoration: none;
    color: white;
    opacity: 0.8;
    }
    
    .navbar ul li a:hover {
    opacity: 1;
    }

The problem lies somewhere in this part of the code, but I can't seem to pinpoint it. Any assistance would be greatly appreciated!

Thank you in advance and warm regards.

Raymond The Hammer

Answer №1

Here is a suggestion for you to try:

<div class="navbar">
            <ul>
                <li>
               <a href="3d.html">3D Printing</a>
                    <ul>

                        <li><a href="#">blah</a></li>

                        <li><a href="#">blah</a></li>

                        <li><a href="#">blah</a></li>

                    </ul>
                    </li>

            </ul>
        </div>

Custom CSS styling:

   .navbar ul {
    position: relative;
    display: inline-block;
    font-family: lemon;
    list-style: none;
    padding: 15px 0px;
    font-size: 210%;
    margin-left: 3%;
    }

    .navbar ul:after {
    content: "";
    clear: both;
    display: block;
    }

    .navbar ul li {
    display: block;
    }

    .navbar ul ul {
    display: none;
    font-size: 100%;
    padding: 18px 5px;
    }

    .navbar ul li:hover ul  {
    display: block;
    }

    .navbar ul ul li {
    background: rgba(0,0,0,0.3);
    border-bottom: 1px solid rgba(0,0,0,0.05);
    }

    .navbar ul ul li:hover {
    background: rgba(0,0,0,0.4)
    }

    .navbar ul li a {
    display: block;
    text-decoration: none;
    color: black;
    opacity: 0.8;
    }

    .navbar ul li a:hover {
    opacity: 1;
    }

Answer №2

.navbar ul li:hover ul  {
display: block;
}

Remember to include a dot before the navbar class

.navbar ul li:hover ul  {
display: block;
}

Check out this jsFiddle example

Note that it is not recommended to use div within ul li tags!

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

Tips for showing various images from a server using ng-repeat

Is it possible to display different images from a server using AngularJS? I have ng-repeat set up for posts and for each post, I want to retrieve its avatar. My approach is to call a function getImage(post.author.id) to fetch the corresponding avatar. $ ...

Tips for detecting if text appears in bold on a webpage using Selenium

I came across a pdf document with the following content: <div class=**"cs6C976429"** style="width:671px;height:18px;line-height:17px;margin-top:98px;margin-left:94px;position:absolute;text-align:left;vertical-align:top;"> <nobr ...

Use a PHP form to send an email with HTML formatting, rather than plain text

I am facing an issue with sending emails from a web form. The received email needs to be displayed as HTML and not text. function createMailBodyLine ( $title, $value ) { $value = nl2br(htmlspecialchars($value)); return "<tr> ...

apply styling to the placeholder with CSS

I have been attempting to customize the styling of the placeholder text. After setting the color to red within the input class, I did not see any changes. Even after conducting research and referring to this link Styling the placeholder in a TextField, I w ...

Compilation of CSS by Webpack resulting in peculiar class identifiers

Currently, I am using webpack for developing a React app with a NodeJS backend. I've encountered an issue with styling the app as webpack seems to be interfering with my CSS, causing changes in class names. For example, in my base.css file, I have d ...

Extracting Tik Tok videos from their URLs using PHP web scraping

I'm attempting to save videos from the following URL: Original: https://api.tiktokv.com/aweme/v1/playwm/?video_id=v09044340000bq0vmd39if221ld9o5n0 The link then changes to this: http://v16m.tiktokcdn.com/e50056249a925719f71ce8618053e173/5eee4e39/vid ...

Tips for updating input placeholder text using CSS

Is it possible to change the placeholder text of an input textbox using only CSS? Here's the HTML code snippet: <div class="col"> <input class="form-control" type="text" placeholder="" id="m ...

How can I effectively access and view HTML files within VSCode while utilizing WSL?

Has anyone else experienced issues with the open-in-browser extension? Whenever I try to open my HTML file for a project, it doesn't load in the browser. I've attempted storing my repository in different directories on Linux and even in a folder ...

What is the best way to acquire an ID that is generated dynamically?

Being new to javascript and ajax, I am facing a challenge. I have a while loop with 2 buttons, both of which seem to function correctly, except for one small issue... The product-id is only being passed for the first or last element in the loop. How can I ...

Change the hover effects on the desktop to be more mobile-friendly

In my desktop version, I have implemented some code that enables hovering over a button to display additional information or text. How can I modify this for mobile so that nothing happens when the button is tapped on? .credit:hover .credit-text, .credit- ...

One way to target a span inside a label element when a checkbox is checked using React Material UI createStyles is by using CSS selectors in combination with

I need help targeting the span element within a checkbox label in order to change its background color when the checkbox is checked. <div className={classes.container}> <input type="checkbox" id="checkboxid" /> <lab ...

CSS - Utilizing Flexbox for creating inline lists that adjust based on text length

I have a set of radio buttons arranged like this: I want to utilize flexbox to display them horizontally when there is sufficient space, similar to this: However, the current setup uses a min-width media query for layout breaking, which can lead to text ...

Create engaging text animation by transitioning from horizontally displayed text to vertically displayed text with the letters standing upright using An

I'm trying to create an animation where an acronym is displayed horizontally in the middle of the screen and then flips vertically. The challenge I'm facing is rotating individual letters once they are vertical so that the text reads from top to ...

What is the best approach to creating a fully rounded capsule using CSS?

I've been having trouble creating a complete capsule in CSS and I'm not achieving the expected outcome. Can anyone assist me in resolving this issue? I am new to CSS. Below is my code: <style> #myStyle { position: relat ...

Saving Data in an Angular Material Table: A How-to Guide

I have a basic angular material table and I am looking for a way to save the data displayed in each row when a button is clicked. Is it possible to save each row of data as an object and push it to an array? If so, how can I achieve this? <div class=& ...

The CSS theme fails to adapt to changes made using jQuery

I encountered a peculiar problem while using a CSS theme with jQuery. After applying a custom CSS theme to a webpage, everything looked fine. However, when I performed certain operations using jQuery - like checking checkboxes causing others to be checked ...

What is the best way to ensure that a specified number of list items (li) will align properly within the width of an unordered list (ul

I'm attempting to make all the li elements' width match that of my ul element. Here is the code I am using: http://jsfiddle.net/4XR5V/2/ I have looked at some similar questions on the website and tried adding: ul { width: 100%; display: tab ...

The mobile website layout appears immaculate on the emulator, but it doesn't translate well on real mobile devices

Recently, I delved into the world of html/css/javascript and decided to create a website as a way to practice my skills. However, I have come to realize that many of the methods I used are not considered best practices. I am committed to improving and will ...

Tips on concealing the visibility of a table row using PHP

My HTML table structure is quite simple: <style> .demo { width:100%; border:1px solid #C0C0C0; border-collapse:collapse; padding:5px; } .demo th { border:1px sol ...

Toggle JavaScript Query Display

Welcome to my HTML test website where I am testing show/hide JavaScript functionality. Upon loading the page, you may notice that everything is hidden until a button is clicked. <html> <head><title>Test</title> <scr ...