Issues with html5 dropdown menu not displaying properly when hovered over

As a beginner in programming, I have been tasked with creating a website using HTML5 and CSS. The main issue I am encountering is with my horizontal menu bar that has vertical sub-menus appearing on hover.

The menu consists of 3 main tabs: Home, Health, and Safety, each with their own set of sub-menus.

While all the main menus seem to be working fine, there is an error when clicking on the "Safety" submenu directly after navigating through the "Home" and "Health" submenus.

The error message reads: "No webpage was found for the web address". This is because the path mentioned for the "Fire Hazards" page is incorrect. It should be located under the "safety/firehazards" folder, not the "health/safety/firehazards" folder as indicated.

I am confused as to why the wrong path is being displayed and causing this issue.

<div id="menu">
  <ul>
   <li><a href="index1.html" class="current">Home</a></li>
   <li><a href="health.html">Health</a>
    <ul>
     <li><a href="health/personal_hygiene.html">Personal Hygiene</a></li>
     <li><a href="health/food_hygiene.html">Food Hygeiene</a></li>

    </ul>
   </li>
   <li><a href="safety.html">Safety</a>
    <ul>
     <li><a href="safety/fire_hazards.html">Fire Hazards</a></li>
     <li><a href="safety/cooking_gas.html">Cooking Gas</a></li>
    </ul>
   </li>
  </ul>
 </div>

CSS

#menu {
    display:block;
    position:relative;
    width: 960px;
    height: 50px;
    background-color: #fff;
    margin: 0 auto;
    border: 1px solid #000;
}
#menu ul li a:hover{
    color: #c1d82f;
}
#menu ul .current {
    color: #b13932;
}
#menu li:hover ul{
    display: block;
}
#menu ul {
    margin: 0;
    padding: 4px 0;
}
#menu  li {
   float: left;
   position: relative;
   list-style-type: none;
}
#menu  li a {
    display: block;
    padding: 10px 45px;
}
#menu ul:after{
    content:".";
    height: 0;
    clear: both;
    visibility: hidden;
}
#menu ul ul{
    position: absolute;
    left: 0;
    display: none;
}
#menu ul ul li {
    width: 100%;
}
#menu ul ul li a{
    border-right: none;
    padding: 5px;
}

/* end of menu */

}

Answer №1

Here is an example of code that you can use:

#menu {
width:100%;
position:relative;
background:#ccc;
}
nav {
position:relative;
}
nav ul {
margin:0;
padding:0;
}
nav ul li {
margin:0;
padding:0;
list-style:none;
display:inline-block;
position:relative;
}
nav ul li a {
font:bold 12px Arial, Helvetica, sans-serif;
text-transform:uppercase;
color:#333;
padding:7px 10px;
display:inline-block;
text-decoration:none;
}
nav ul li:hover > a {
text-decoration:none;
color:#005ba0;
}
nav ul li a.current {
background:#005ba0;
color:#fff;
}
nav ul ul {
min-width:200px;
position:absolute;
top:100%;
z-index:666;
background:#eee;
display:none;
}
nav li:hover > ul {
display:block;
}
nav ul ul ul {
left:100%;
top:0;
}
nav ul ul li {
display:block;
width:100%;
}
nav ul ul a {
padding:7px 10px;
display:block;
color:#777;
border-bottom:1px solid #ddd;
text-align:left;
}
nav ul ul a:hover {
background:#ddd;
}
nav ul ul a.current {
background:#dddd;
color:#005ba0;
}
<div id="menu">
<nav>
<ul>
<li><a href="index1.html" class="current">Home</a></li>
<li><a href="health.html">Health</a>
<ul>
<li><a href="health/personal_hygiene.html">Personal Hygiene`enter</a></li>
<li><a href="health/food_hygiene.html">Food Hygeiene</a></li>
</ul>
</li>
<li><a href="safety.html">Safety</a>
<ul>
<li><a href="safety/fire_hazards.html">Fire Hazards</a></li>
<li><a href="safety/cooking_gas.html">Cooking Gas</a></li>
</ul>
</li>
</ul>
</nav>
</div>

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

After the initial iteration, the .length function ceases to function properly when

A validation method is set up to check the length of a user input field. It functions properly on the initial try, but does not update if I go back and modify the field. $("#user").blur(function () { if ($("#user").val().length < 3) { $("#userval ...

Utilizing HTML imports in Typescript for efficient use as TemplateStringLiteral

Recently, I started using TypeScript for the first time and I'm looking to integrate it into my webpack build. Currently, I am working with ts-loader and babel-loader to load TypeScript files while also attempting to include HTML files within the scr ...

The application has encountered an unexpected error and is currently unavailable

This is the code snippet for my MainActivity.java file. I am developing a simple LoginApp. However, when I try to run the app, it displays an "unfortunately stopped working ERROR..." message. package com.example.loginapp; import android.os.Bundle; import ...

Having the title inside the <head> tag will display it on the page

I recently created a simple website, but I noticed that the title is appearing on the page instead of in the head section where I originally placed it. When I checked using the inspect tool in Chrome, I found that the title tag was actually inside the body ...

Error encountered in ngtsc(2345) where an argument of type 'Event' is being used instead of an expected parameter type of 'SortEvent'

I recently started using angular and encountered an issue while trying to sort columns. The error message I received was: Argument of type 'Event' is not assignable to parameter of type 'SortEvent'. Type 'Event' is missing t ...

Managing the scrolling direction horizontally with waypoints.js

As I work on creating a custom wizard form with waypoints, I've encountered an interesting issue that has left me puzzled. In my sample CODEPEN, you can see two pages of the wizard process to better understand the problem. Upon clicking the forward ...

PHP updating data in a MySQL database

I've been using easyPHP and encountering issues with updating records in my database. Whenever I try to update, the HTML form displays and instead of updating the data. However, it does print "Updated dat ...

Experiencing repeated triggering of ng-change on 'range' input in Chrome

When the range input is changed by sliding, the ng-change function continues to be triggered repeatedly until another element is clicked. This issue seems to occur only in the Chrome browser. You can view an example on this fiddle. Try sliding the element ...

single-use date availability checker

I'm currently facing an issue with my code. It seems to be functioning correctly, but only for the first iteration. Let me explain further. If I select a date and time that is already in the database, it correctly displays "date unavailable". Likewis ...

I'm encountering a Python Selenium error related to the timing of webpage loading

# Specifying the path to the chromedriver program service = Service('C:\Program Files (x86)\Google\chromedriver.exe') service.start() # Opening a remote connection with robinhood website using the driver driver = webdriver.Remote( ...

Tips for validating html:options collection in Struts 1.3?

A Treemap is populated with values from a database using the following Java code: Map<String, String> treeMap = new TreeMap<String, String>(map); Iterator mapIterator = mapSet.iterator(); while (mapIterator.hasNext()) { Map.Entry mapEntry = ...

What is the best way to make sure that the parent div of an svg shows its shadow on top of the svg itself?

I am in the process of creating an interactive world map using an SVG map. The SVG format is necessary because I have implemented functionality to zoom in and move the map around. However, a challenge has arisen: the SVG element is obstructing the shadow o ...

Retrieve data from an API and store it in a JSON array

My website is having an issue where it's fetching data from an API and displaying it in a table, but all the cells are returning undefined values. The data in the API is structured as an array with multiple datasets inside curly braces that I am unsu ...

What is the approach taken by NextJS for ensuring the security of pages when attempting to access them directly in the browser

What happens in NextJS when an unauthorized user tries to access secure pages directly in the browser? Currently, I am attempting to view the /dashboard (which is a secure page). The dashboard DOM elements are displaying. Please refer to the screenshot be ...

Guide to effectively retrieving data from S3 and displaying a view at regular intervals of 4 seconds

In my current project, I am working on fetching a file from S3 and utilizing the data within that file to generate a map on a webpage. To achieve this task, I have set up an Express server along with the EJS templating engine for serving and rendering the ...

Retrieve the id of the anchor tag that was selected upon clicking, and then dynamically change the content of another div

Seeking guidance on how to dynamically change the content of a div element based on which anchor tag is clicked. Below is the HTML structure and JavaScript function I have attempted: HTML: <div> <a id="a1" href="javascript: changeDiv();">tag1 ...

CodePen displaying CSS errorsI'm having trouble getting my CSS

I'm facing an issue with my CSS code and I need your help to figure out what's wrong. I believe it's a simple problem that someone can quickly identify just by looking at the code. Any assistance would be greatly appreciated! Here is the co ...

Building an Angular 4 app featuring a customized default landing page and URL parameters functionality

I am in the process of developing a web portal that will be embedded within an iFrame. Below is the code snippet I am using to set up the portal: Routes Configuration const routes: Routes = [ { path: '', redirectTo: '/dash ...

How to align an image in the center of a circular flex container

I'm facing an issue in my Angular project where I have the following code snippet: onChange(event: any) { var reader = new FileReader(); reader.onload = (event: any) => { this.url = event.target.result; }; reader.readAsData ...

Steps to create a submit button that is linked to a URL and includes an image

I'm attempting to convert my submit button into an image that, when clicked, redirects to another page. Currently, the submit button is functional but lacks the desired image and href functionality. <input type="submit" name="submit" alt="add" o ...