Attempting to develop a dropdown menu with the use of HTML5 and CSS

I've been grappling with this issue for a few days now and thought I'd seek help from the online community. My goal is to create a sub-menu that pops up when hovering over a link. While I've managed to get it to work somewhat, the links in the menu appear on the webpage without any formatting. Any assistance or advice would be greatly appreciated.

Here's the Fiddle

Thank you in advance.


HTML code

<body>

        <nav>
        <ul><li><a href="index.html">home</a></li>      

        <li><a href="#">venue</a>
        <ul class="hidden"> <li><a href="venue.html">address</a></li>
        <li><a href="venue.html#background">venue background</a></li>
        <li><a href="venue.html#instructors">instructors</a></li></ul> </li>

        <li><a href="wakeboarding.html">wakeboarding</a>
        <ul class="hidden"> <li><a href="wakeboarding.html">background</a></li> 
        <li><a href="wakeboarding.html">future</a></li></ul> </li>

        <li><a href="events.html">up-coming events</a>
        <ul class="hidden"> <li><a href="events.html">professional</a></li> 
        <li><a href="events.html">amateur</a></li> </ul></li>

        <li><a href="prices.html">prices</a>
        <ul class="hidden"> <li><a href="prices.html">prices</a></li> 
        <li><a href="events.html">special offers</a></li></ul> </li>

        <li><a href="contact.html">contact us</a></li></ul>
        </nav>

        <img src = "logo.png"
         alt = "Logo" />

        <form>
            <input type="email" required placeholder="sign up for newsletter" /> <input type="submit" value="submit">
        </form>

    </body>
<br />

CSS code

body nav > ul >  li {

list-style-type: none;
position: intial;
top: 110px;
//right: -200px;
display: inline;

}

body nav > ul .hidden   {


opacity: 1;
position: relative;

}

body nav > ul > li:hover  >.hidden  {

visibility: visible;
display:block;
position:absolute;
top:10x;

}



body nav ul li  {

display: inline;
padding: 80px;
font-family: Geneva,Tahoma,Verdana,sans-serif; 
font-size: 24px; 

}

Answer №1

Check out this helpful resource:

https://jsfiddle.net/Edrees21/ae55p7u1/2/

<div class="nav">
    <ul>
        <li class="main-menu-item">
            <a class="link">Link 1</a>
            <ul class="sub-menu">
                <li>Sub menu 1</li>
                <li>Sub menu 2</li>
                <li>Sub menu 3</li>
            </ul>
        </li>
        <li class="main-menu-item">
            <a class="link">Link 2</a>
            <ul class="sub-menu">
                <li>Sub menu 1</li>
                <li>Sub menu 2</li>
            </ul>
        </li>
        <li class="main-menu-item">
            <a class="link">Link 3</a>
            <ul class="sub-menu">
                <li>Sub menu 1</li>
                <li>Sub menu 2</li>
            </ul>
        </li>
    </ul>
</div>

CSS ul { list-style: none; margin: 0; padding: 0; }

li {
    padding: 5px;
}

.main-menu-item {
    position: relative;
    cursor: pointer;
}

.main-menu-item:hover > ul {
    display: block;
}

.sub-menu {
    display: none;
    position: absolute;
    left: 80px;
    top: 0;
}

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

Ways to alert user prior to exiting page without initiating a redirect

I have a feature on my website where users can create and edit posts. I want to notify them before leaving the page in these sections. Here's how I can accomplish that: //Add warning only if user is on a New or Edit page if(window.location.href.index ...

What is causing the parse error in my CSS code?

Running into a parse error on line 314 of my css (style.css). The error is "} expected css(css-rcurlyexpected)". Even after adding the necessary curly brace, it still doesn't validate. Below is my CSS starting from line 314 till the end: /* CSS code ...

What is the best way to iterate through this using forEach?

let array = [{ query:{ q1 : 123, q2 : 44 } }]; Despite attempting to use a forEach loop, no results were returned. ...

Avoid the need to refresh the HTML content every time there is a change in the Angular $

One of the challenges I'm facing is with a for loop in my JavaScript: for (var i=0;i<2;i++) { $scope.widget = widgets[i]; $scope.header = widgets[i].data.header; $scope.items = widgets[i].data.items; $scope.footer = widgets[i].data ...

Determine the quantity of particular information within an array of objects

My goal is to calculate the total number of entries based on the color provided by the user. For instance, if the user enters 'red', the program should return 11. I attempted to achieve this but encountered an issue with the variable cnt not bein ...

What could be causing my custom CSS to not take effect on a progress bar within my JSP page?

Struggling to incorporate a progress bar into my JSP page to track order status, I'm facing issues with applying custom CSS. Despite using !important to override conflicting styles, it seems like other frameworks (such as Bootstrap) might be taking pr ...

Is the shape of the Shadow in Three.js r76 MeshLambertMaterial unusual?

When using r70, the shadow appears as expected - r70 example (Shadow correct shape) However, with r76, the shadow appears abnormally shaped - r76 example (Shadow abnormally shaped) It is noticeable that the shadows on the MeshLambertMaterial on the groun ...

C# on Windows Phone: The issue of MaxWidth and MaxHeight property being overlooked

As I organize my Canvases within a ListBox, I encounter an issue with the TextBlocks inside. Despite setting MaxWidth/Height or standard Height/Width properties on the TextBlock elements, these settings seem to be disregarded. This leads to text overflowin ...

Selenium server is not running and causing a connection refusal

Recently, I took over a project at work that lacks any documentation. The project is built on sails.js and includes a small number of unit tests along with an end-to-end test. Unfortunately, when attempting to execute the end-to-end test using grunt, the ...

Is it possible to use two onChange functions in a single text field with ReactJS?

Is it possible to have two onChange functions in a single Textfield? In my code, "onChange={ showDiv}" is a handler that shows "Direct 2" when clicked and hides upon selecting option1. The second onChange={(e) => exhandleChange(e)} is used for another ...

Step-by-step Guide on Utilizing Puppeteer for Web Scraping a Reddit Page

Currently, I am attempting to grasp the concepts of using Puppeteer for web scraping on a reddit page. The new version of reddit boasts dynamically added content and infinite scrolling. However, I have encountered inconsistent outcomes with my code and I a ...

Vibrant array of colors in AmCharts' line graphs

I'm looking to enhance my graph by having lines between the bullets in different colors based on their direction. For instance, if a line is rising (going from a bullet of smaller value to greater value), it should be green; if a line is falling, it s ...

Creating code that is asynchronous using an event-driven architecture

When programming in node.js, I often find async functions to be quite messy. I would like to write async code that retrieves data as events occur. I am familiar with promises, but they are not quite what I am looking for. What I am seeking is something sim ...

Changing Time to Extended Form in AngularJS

Currently, I have an input box that is displaying the time in the format HH:mm AM/PM. <input type="text" ng-model="myTime" required/> To achieve this, I am utilizing the date filter in AngularJS - $scope.myTime = $filter("date")(new Date(), &apos ...

Enhancing quiz results with intricate input forms using JavaScript

I am currently working on an online quiz and the code is functioning properly. However, I would like to display the scores of each user. As a beginner in Javascript, I have been developing this quiz for a friend, and it has been a learning experience for m ...

Mapping an array using getServerSideProps in NextJS - the ultimate guide!

I'm facing an issue while trying to utilize data fetched from the Twitch API in order to generate a list of streamers. However, when attempting to map the props obtained from getServerSideProps, I end up with a blank page. Interestingly, upon using co ...

Creating Sub Menu in Blogger with pageListJSON

I am looking to enhance the menu on my blog by adding a sub-menu structure. Specifically, I want to organize my menu to include "Manual Testing" and "Automated Testing" as sub-menus under the main category of "Testing". Testing Manual Testing Automated ...

"Implementing a feature in Django that clears the input field upon clicking the clear button

I am working on a Django HTML file that includes an input field and a clear button. I need to clear the input field when the clear button is pressed. Is it necessary to use JavaScript for this task, or is there another way to achieve it? <form> ...

Testing the React component with the useRouteMatch hook by running a unit test

Consider the code snippet below: import React, { useState, useEffect } from 'react'; import { createPortal } from 'react-dom'; import { useRouteMatch, Link } from 'react-router-dom'; interface MyComponentProps { myId?: stri ...

Switch out multiline text with javascript

Could someone assist me with this question? I am attempting to locate and replace specific code within a JavaScript file. The code is included in an AJAX response that contains a significant amount of HTML code. After retrieving the AJAX response, I stor ...