Crafting web design with CSS and HTML programming

I am currently working on implementing a sublevel drop-down menu. While I have successfully created the first level of the menu, the second level always displays prominently when hovering over the first drop-down menu. My goal is to only show the second level when hovering over the first level. Any assistance or guidance provided would be highly appreciated. Below is the HTML code I am using:

HTML

<nav>
   <ul>
      <li><a href="#"><span></span> Home </a></li>
      <li>
         <a href="#"><span></span> Jewelry </a>
         <ul>
            <li>
               <a href="#"><span></span> Rings </a>
               <ul>
                  <li><a href="#">Silver</a></li>
                  <li><a href="#">Copper</a></li>
                 <li><a href="#">Bronze</a></li>
               </ul>
            </li>
            <li><a href="#"><span></span> Pendants </a></li>
            <li><a href="#"><span></span> Bracelets </a></li>
            <li><a href="#"><span></span> Necklaces </a></li>
            <li><a href="#"><span></span> Other </a></li>
         </ul>
      </li>
      <li><a href="#"><span></span> Testimonials </a></li>
      <li><a href="#"><span></span> Latest Offers </a></li>
      <li><a href="#"><span></span> News </a></li>
      <li><a href="#"><span></span> Contact Us </a></li>
   </ul>
</nav>

CSS

nav {
    background: url(texture.png);
    width: 210px;
    margin: 20px;
}

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

nav ul li {
    position: relative;
}

nav ul li ul li ul li {
    position: block;
}

nav a {
    color: #e8e8e8;
    padding: 12px 0px;
    display: block;
    text-decoration: none;
    transition: background 1s;
    -moz-transition: background 1s;
    -webkit-transition: background 1s;
    -o-transition: background 1s;
    font-family: tahoma;
    font-size: 13px;
    text-transform: uppercase;
    padding-left: 20px;
}

nav a:hover {
    background: RGBA(255,255,255,0.05);
    color: #fff;
}

nav ul li:hover ul {
    display: block;
}

nav ul ul {
    position: absolute;
    left: 210px;
    top: 0;
    border-top: 1px solid #e9e9e9;
    display: none;
}

nav ul ul li {
    width: 200px;
    background: #f1f1f1;
    border: 1px solid #e9e9e9;
    border-top: 0;
}

nav ul ul li a {
    color: #a8a8a8;
    font-size: 12px;
    text-transform: none;
}

nav ul ul li a:hover {
    color: #929292;
}

nav span {
    width: 12px;
    height: 12px;
    background: #fff;
    display: inline-block;
    float: left;
    margin-top: 3px;
    margin-right: 20px;
    position: relative;
    transition: all 0.5s;
    -moz-transition: all 0.5s;
    -o-transition: all 0.5s;
    -webkit-transition: all 0.5s;
}

nav a:hover span {
    background: #7d2c41;
    transform: rotate(90deg);
    -moz-transform: rotate(90deg);
    -webkit-transform: rotate(90deg);
}

nav span:before {
    content: "";
    width: 12px;
    height: 2px;
    background: #3a3b3b;
    position: absolute;
    left: 0px;
    top: 5px;
}

nav span:after {
    content: "";
    width: 2px;
    height: 12px;
     background: #3a3b3b
    position: absolute;
    left: 5px;
    top: 0;
}

Answer №1

To achieve the desired effect, modify the hover selector as follows:

nav ul li:hover > ul

By making this adjustment, only the first child ul element will be displayed when hovered over.

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

Trouble with HTML5 Geolocation Functionality

I am having an issue with my Geolocation code. It works fine when I run it on my desktop, but when I upload it to a free hosting service like [http://darkdays.byethost14.com/cc.html], the button does not work and nothing pops up. Can anyone help me trouble ...

Transforming a Joomla template into a standard HTML template

I have a question about Joomla. Although I already have a Joomla template that was not originally intended for use with Joomla, I would like to utilize it as an HTML template so I can easily modify and edit it without using Joomla. Therefore, I am looki ...

What other technique can I use to replace the creation of a jquery division?

I`m relatively new to all things related to web technologies and I am currently practicing and learning about them. On my practice page, I've experimented with various elements, including changing div heights based on the viewport height. Here's ...

index.html: using jquery for selecting colors

I attempted to integrate a jQuery plugin into my application, but it doesn't seem to be working. In the head section of my code, I have included: <link rel="stylesheet" media="screen" type="text/css" href="./style/colorpicker.css" /> <script ...

Github website logo not displaying properly

Struggling to display my favicon on my website created with Github. I've tried using the code <link rel="shortcut icon" type="image/x-icon" href="favicon.ico">, but it's not working. Can anyone provide me with the correct code? I am using B ...

What is the most efficient way to combine a parameter string within a JavaScript function and append it to an HTML string?

Welcome to my HTML code snippet! <div id="content"></div> Afterwards, I add an input to #content: $( document ).ready(function() { // Handler for .ready() called. var parameter = "<p>Hello</p>"; $("#content").appe ...

Show a div once all its content has been fully loaded

I have a section on my webpage that includes images, text, and links. It functions as a carousel. My goal is to show the section only after all content has loaded. I am looking to transition from opacity 0 to opacity 1 with a fade-in effect. Here is the ...

Material-UI is having trouble resolving the module '@material-ui/core/styles/createMuiTheme'

Although I have searched for similar issues on StackOverflow, none of the solutions seem to work for me. The errors I am encountering are unique and so are the fixes required, hence I decided to create a new post. The company conducting my test provided m ...

Is there a way to conceal/remove the text displayed on the submit button?

I am facing an issue with a submit button in my PHP code. The button displays an integer value that is crucial for running a script, but I want to hide the value as it interferes with the design using CSS. I have attempted various solutions like removing t ...

How can we call a function in HTML from an external JavaScript file?

I am attempting to utilize a function that I have defined in my .js file within my HTML document. js/newsalerts.js function decodeHTML(html) { //https://stackoverflow.com/a/2989105/4650297 var tempDiv = document.createElement("DIV"); tempDiv. ...

Is the Packery image grid only functional when the background image is specified in CSS and not in JavaScript? Perhaps we need to look into using Await/Sem

I've successfully implemented a packery image grid that is responsive and functional when the background image in the .item-content section is defined in the CSS file: http://codepen.io/anon/pen/eJdapq .item-content { width: 100%; height: 100%; ...

Block users from viewing the image displayed within a JavaScript canvas

On my server, I have a path to an image that is accessed by a JavaScript to load the image onto a canvas. The script then proceeds to hide certain parts of the image using black layers. The issue arises when a user can easily view my JavaScript code, extr ...

Getting the list items separated from the unordered list in Selenium

My current task involves navigating a list and selecting the correct text entry. The list contains only 2 items: <ul> <li><span>first</span></li> <li><span>second</span></li> </ul> However, ...

Adjusting the Size of a Static Banner

I have a quick question. I've been trying to create a fixed banner that will scale when the page is resized, but I'm having some trouble with the phrasing in Google search. My issue is that when using a percentage width for the large container, t ...

What is the best way to give a decorative border to a pseudo-element's before content?

Hey there, I have a question. I created a block with a protruding corner at the top and applied a corner effect using box-shadow. How can I achieve the same effect for a pseudo-element (.comment_text:before) https://i.sstatic.net/laEIJ.png .comment{ ...

Creating a Stylish Navigation Bar with Bootstrap4 - Organizing Elements for Just the Right Look

I am trying to organize my content within a navbar into 3 different 'columns'. I want a logo on the left, some navigation items in the center, and the last element ("Get The App") on the right, but I am facing some challenges. Below is my code s ...

Show a distinct cursor when hovering over text (excluding the element)

When the default cursor hovers over text, it switches to a caret-shaped cursor. This behavior only occurs when hovering over text; if you hover elsewhere inside the element, the specific cursor will not be displayed. For example, I am aiming for a setup s ...

Ways to make video controls visible following the initial click on the video

I have a collection of videos on my website and I would like them to display with a poster (thumbnail image) initially. The video controls should only appear once the user clicks on the video for the first time. Therefore, when the page is loaded, the cont ...

Altering hues upon clicking the link

I'm looking for a way to set up my menu in the header using "include/header.php" and have it so that when I click on a link, it takes me to that page while also changing colors to indicate it's active. Would jQuery or PHP be more suitable for thi ...

Having trouble displaying several thumbnails side by side

I am looking to display thumbnails in a row, but they are currently showing up in a single column. I have tried correcting the row class in the HTML template provided, but it is not displaying as desired. Here is how it looks like now {% extends "ba ...