Difficulty maintaining hover state on menu while navigating to submenu on an HTML page

I successfully implemented a side menu that displays the submenu when hovering over menu items. However, I am encountering two issues: 1. When I hover over a menu item and the submenu appears, the hover state of the menu item disappears. I would like the menu item to remain in the hover state. 2. The submenu block appears transparent, allowing the contents behind it to show through. How can I make it completely opaque?

Here is the code I am using...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>CSS Drop Down Menus</title>

<style type="text/css">
<!-- * {
    margin: 0;
    padding: 0;
}

body {
    font-family: "Trebuchet MS", Helvetica, Sans-Serif;
    font-size: 14px;
} -->

a {
    text-decoration: none;
    color: #FFFFFF;
}

a:hover {
    color: black;

}

#menu {
    position: relative;
    width:20%;
    height:400px;
    border:1px solid #000;
}

#menu a {
    display: block;
    width: 140px;
    background-image:url(menuitemhover.png);
}

#menu ul {
    list-style-type: none;
    padding-top: 5px;
}

#menu li {
    float: top;
    position: relative;
    padding: 3px 0;
    text-align: center;
}

#menu ul.sub-menu {
    display: none;
    position: absolute;
    top: -10px;
    left: 170px;
    padding: 10px;
    z-index: 90;
}

#menu ul.sub-menu li {
    text-align: top;
}

#menu li:hover > ul.sub-menu {
    display: block;
    border: 1px solid #ececec;
    background-image:url(menuitemhover.png);
}
</style>

</head>
<body>

<div id="menu">
    <ul>
        <li><a href="#">Home</a>

        <ul class="sub-menu" style="border:1px solid #d14836"}>
            <li><a href="#">Pages</a></li>
            <li><a href="#">Archives</a></li>
            <li><a href="#">New Posts</a></li>
            <li><a href="#">Recent Comments</a></li>
        </ul>

        </li>

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

        <ul class="sub-menu" style="border:1px solid #d14836">
            <li><a href="#">Get to know us</a></li>
            <li><a href="#">Find out what we do</a></li>
        </ul>

        </li>

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

        <ul class="sub-menu" style="border:1px solid #d14836">
            <li><a href="#">E-mail Us</a></li>
            <li><a href="#">Use Our Contact Form</a></li>
        </ul>

        </li>
    </ul>
</div>

</body>
</html>

Answer №1

It seems like what you're looking to do is add a background color to the #menu li:hover > ul.sub-menu and also to #menu a. To make things easier for testing purposes, consider using bold colors like green or red. Once you've completed testing, feel free to replace the colors with your desired choices.

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

Double-click required to toggle button

Here is the code snippet for controlling an LED using a web page. The script, linked to Python, effectively controls the LED. However, there is an issue where the button toggles to the right side (ON position) only after a double click. Upon first click ...

Using jQuery to select a specific checkbox from a group of checkboxes with identical IDs

There is an issue with multiple checkboxes having the same ID in an asp.net repeater control. Users can select either email or phone against each record in the repeater rows. In the example below, there are two rows. If you select the email icon in the fi ...

Alter a portion of the style using jQuery

After attempting to use jQuery to change the style of a specific element, I was surprised to find that it didn't work as expected. The typical process for changing the style involves the following code: $(document).ready(function(){ $("p").css({" ...

Achieving vertical center alignment for the label and btn-group in Bootstrap

Is it possible to align other elements with the Bootstrap btn-group? <div class="btn-toolbar text-center"> <div class="pull-left"> <span class="glyphicon glyphicon-envelope " style="font-size:1.5em;"></span> < ...

Position a dynamic <div> in the center of the screen

My goal is to design a gallery page with a list of thumbnails, where clicking on a thumbnail will open the related image in a popup div showing its full size. The issue I'm facing is how to center the popup div on the screen, especially when each pic ...

How can I bind Angular to the selection of a file input field?

I am facing an issue with my upload form where the displayed filename is showing a virtual filepath instead of just the filename itself. How can I improve the binding to only display the filename (like selected.files[0].name) without any virtual path? My ...

What causes the device pixel ratio to vary across different web pages on the same device and operating system?

I am curious about why device pixel ratio varies between different websites and operating systems. For instance, when using the same device, this site displays a different pixel ratio on Windows compared to Ubuntu. On Windows, the pixel ratio is 1.34 whi ...

Is it possible to extract style information using Selenium WebDriver in Python?

I am currently attempting to extract the specific typography used by a company on Stylify Me (e.g. for I am interested in retrieving "UberMove, 'Open Sans', 'Helvetica Neue', Helvetica, sans-serif, normal, 52px, 56px, #000000"). Howeve ...

Identifying when a page-loading or reloading event has been canceled

When the Cancel button is pressed during page load/reload, the content of the page loads partially. Is there a more effective way to address this issue rather than displaying incomplete content? For instance, consider showing a message such as "Page load ...

Transferring data from an Excel spreadsheet into a structured table

I am interested in transferring specific columns of data from an excel sheet to an HTML table. My goal is to populate the table based on certain conditions rather than statically inputting fixed cells. For instance, if my excel sheet has columns for Name ...

Tips for executing a Python function from JavaScript, receiving input from an HTML text box

Currently, I am facing an issue with passing input from an HTML text box to a JavaScript variable. Once the input is stored in the JavaScript variable, it needs to be passed to a Python function for execution. Can someone provide assistance with this pro ...

How to Use JavaScript Function to Rotate an Entire Webpage

For my final project in a web design class, we were tasked with creating a website that showcases our skills. I've completed the assignment and now I want to add some interesting features to make it stand out. I'm interested in using -webkit-tra ...

Overlaying images responsively on top of each other

I have successfully achieved the result of displaying an image over another image using the following code: <div class="row"> <div class="col-lg-6 col-md-6 col-sm-12"> <div class="image-with-overlay"> <div clas ...

Ways to conceal rows within an implicit grid

In the code snippet below, CSS Grid is used to adjust the number of columns for wider containers. When dealing with narrower containers (such as uncommenting width: 80vw or resizing the example), implicit rows are added (with only two being specified in th ...

Ways to apply CSS styles dynamically within a v-for loop

Despite searching through the VUE official website and various other sources, I have not been able to find a satisfactory solution. I am reaching out for assistance, thank you in advance. <div class="tag-item" :ref="`tagItem_ ...

Show the first letter of the first name using HTML

Is there a way to display the first letter of the first name followed by a period, a space, and then show the last name in asp/html/vb? ...

What is the best way to trigger a method once an image has completed loading and rendering?

Is there a way to trigger a method once an image has finished loading and displaying on the web browser? Here's a quick example using a large image: http://jsfiddle.net/2cLm4epv/ <img width="500px" src="http://www.digivill.net/~binary/wall-cover ...

Caching HTML5 videos in Google Chrome

I am currently in the process of building a website and have successfully added an HTML5 video. However, I encountered an issue when attempting to change the video file in the background for users to upload a new one. Despite updating the video URL, Chro ...

Tips for dynamically setting up an inputStream in a Java <audio> tag within an HTML5 environment

I need to incorporate a dynamic inputStream from a web service into an HTML5 audio tag so that users can play it. How can I programmatically set the content of the HTML5 tag to achieve this? ...

When you have a target element that is deeply nested, consider using a 50% height relative to

There is some confusion surrounding the issue below: <div class="container"> <div class="row"> <div class="group"> <a> <div class="col-lg-3 full-h"></div> </a> <a> < ...