creating a nested dropdown menu with CSS

Experimenting with a nested drop-down menu using basic CSS. I am creating a navigation menu. Everything seems to be working fine, except for the issue that arises when hovering over the ABOUT US section under NEW HERE. It displays the correct result, but the problem is that it does not disappear when hovering over the next section below it. How can I fix this? Here's The Link For the snippet for you to review. Please let me know where I might be going wrong. here's the code for your reference..

   .dropbtn2
  {
    position: relative;
    display: none;
  }
  .dropdown {
    position: relative;
    display: inline-block;
  }

  /* Dropdown Content (Hidden by Default) */
  .dropdown-content {
    display: none;
    position: absolute;
    background-color: #f9f9f9;
    min-width: 169px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    z-index: 1;
  }

  /* Links inside the dropdown */
  .dropdown-content a {
    color: black;
    font-size:20px;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
  }

  /* Change color of dropdown links on hover */
  .dropdown-content a:hover {background-color: #f1f1f1}

  /* Show the dropdown menu on hover */
  .dropdown:hover .dropdown-content {
    display: block;
    transition:none;
  }
  .dropdown-content a:hover {
    padding-top:15px;
    transition:ease-in-out .5s;
  }
  .dropdown:hover .dropbtn
  {
    background-color: #8300ff;
    color: #182318;
    padding-top: 500px;
    padding-bottom: 30px;
    padding-right: 20px;
    padding-left: 20px;
    transition: ease-out 0.5s;
    text-decoration: none;
    box-shadow:none;

  }
  /* End*/
  .dropdown-content2 {
    display: none;
    position: absolute;
    background-color: #f9f9f9;
    min-width:170px;
    left:170px;
    top:0;
    z-index: 1;
  }

  /* Links inside the dropdown */
  .dropdown-content2 a {
    color: black;
    font-size:20px;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
  }

  /* Change color of dropdown links on hover */
  .dropdown-content2 a:hover {background-color: #f1f1f1}

  /* Show the dropdown menu on hover */
  .dropdown-content:hover .dropdown-content2 {
    display: block;
    transition:none;
  }
  .dropdown-content2 a:hover {
    padding-top:15px;
    transition:ease-in-out .5s;
  }
  .dropdown a:hover .dropbtn2
  {
    padding-bottom: 30px;
    padding-right: 20px;
    padding-left: 20px;
    transition: ease-out 0.5s;
    text-decoration: none;
    box-shadow:none;

  }

  /*TEST*/

Answer №1

To ensure that your dropdown-content only appears when hovering over your initial link, you will need to adjust the element to hover.

You can make this change at line 182 in your codepen. Replace

dropdown-content:hover .dropdown-content2
with
.dropdown2:hover .dropdown-content2
.

Lines 181-185:

  /* Display the dropdown menu on hover */
  .dropdown2:hover .dropdown-content2 { /* Make the necessary adjustment for hover here */
    display: block;
    transition:none;
  }

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

When viewed on a mobile device, the entire HTML document is resized to occupy less than half of the

Whenever I adjust the size of my webpage on different devices or mobile phones, I notice that the <div> tag appears to be only half (or even less) the width of the page. This gap seems to increase as the window size decreases. Refer to the screenshot ...

What causes an absolutely positioned element to be positioned by its sibling rather than at the top corner of the page?

Can someone explain to me why my absolutely positioned element is displaying after my child_static div? I'm under the impression that absolutely positioned elements are removed from the normal flow. So why isn't child_absolute covering the child_ ...

Update Symfony form class to replace the HTML5 input type from "text" to "number"

Attempting to implement an input with the "number" type for HTML5 frontend support has been a challenge. Here is my form class: class MyType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { ...

The percentage of occurrences for each result with the specific id

In my database, I have a table that looks like this: Currently, in my PHP code, I am performing a SUM operation like this: function calculate_percentage() { $sql = "SELECT (sum(distance))/(25000)*(100) as totaldistance1 FROM axle WHERE train_id = ...

How can I retrieve the results of an SQLite call in HTML5 without passing them to a separate function?

How can I use SQLite in HTML5 to execute a call like the one below, so that the result is returned immediately rather than passed off to another function? try { mydb.transaction( function(transaction) { transaction.executeSql( &apo ...

The issue of consistently receiving a null value when trying to choose a selection from a

The drop-down menu below failed to meet the required criteria in my validation and kept prompting me to select an option, even though one had already been chosen. <div class="col"> <label for="#">College Degree</label ...

JQuery Ajax: Issue with updating Total Likes for posts when Like button is clicked

There are two JQuery Ajax calls in this scenario. The first call retrieves user messages from MySQL, along with the number of likes for each message and a button for users to like the message. This initial request is functioning correctly. The second Ajax ...

By utilizing Angular's @output decorator, data can be passed from child components to their parent counterparts

I have a situation where I am passing data from a child component to a parent component, and I need to automatically check if the data is empty or has a value. This code snippet is from my login.component.ts - child TypeScript file: @Output() update = ne ...

Tips on reducing the size of a display:block

Beginner in programming. I'm having trouble with my signature design. The block in the background is sticking out on both sides. How can I adjust its size? <td> <a href="https://twitter.com/TEST" color="#252e42" class="sc-hzDkRC kpsoy ...

The div elements are constantly shifting positions when viewed in Internet Explorer

After completing my website and testing it across different browsers, I noticed an issue with IE. The contact div and navigation shift around the page in this browser specifically. Can anyone help me out with some code to fix this problem? Link to live ex ...

Using Tailwind CSS to center a NexJS <Image /> component within a modal

In an effort to style my MapBoxGL popup content, I am working on aligning the text above the image to the left and centering the image below within the popup. As shown in the image below, this is currently proving to be a challenge as I transition from usi ...

Strategies for restricting user input within a datalist

I have a project in which I am creating a webpage that displays a list of flights that can be filtered by destination, origin, price, and more. To achieve this, I have categorized each flight within a div element using its specific properties as classes. F ...

The issue of a background image not appearing on Chrome and Firefox has been identified

I am experiencing an issue where a background image is not showing up on Chrome or Firefox, but it displays properly on other browsers. The problem occurs with relative and hard links Substituting the image file works, but the video disappears Adblock is ...

Is it necessary for each React component to have its own individual stylesheet?

Looking for some advice on React as a newbie here. I'm wondering whether each React component should have its own stylesheet. For instance, if I have my main App component that gets rendered to the browser, is it sufficient to include a CSS file the ...

Steps to ensure that a particular tab is opened when the button is clicked from a different page

When I have 3 tabs on the register.html page, and try to click a button from index.html, I want the respective tab to be displayed. Register.html <ul class="nav nav-tabs nav-justified" id="myTab" role="tablist"> <l ...

arrangement of form labels in material-ui

Is there a way to configure the labels in Material-ui + react forms to be displayed beside input fields for better readability? For example: name [input] title [input] instead of name [input] title [input] I have looked through the documentation b ...

"Enhancing security measures with multiple nonce for Content Security Policy

I am encountering an issue with my single page application, which is developed in .net core MVC 2.2. The application loads html sections on the fly. In the main document, I have added a Content Security Policy (CSP) policy with a dynamically generated hea ...

Is it possible to reset the text within the text box when the form is being submitted using the load() ajax function?

I am working on implementing a comment feature where the data entered in the form is appended and displayed after submission. Here is my HTML form: <table> <tr><td>Name :</td><td> <input type="text" id="name"/></td&g ...

Tips for avoiding table column overlap during window resizing situations

My current issue involves using a table to present information. While resizing the window, I noticed that the columns in the table were overlapping. Below is the code snippet: <table style="width:100%;table-layout:fixed"> <tr style="border-bo ...

PHP form redirection is a useful feature that allows website developers to

I have created a PHP contact form on WordPress that redirects users based on their selected region. I have used 'www.google.com' as a test URL, but the form is redirecting to the custom theme page I built on WP instead. What am I doing wrong? ...