Problem with items overlapping in hoverable drop-down menu

I have been attempting to create a hoverable dropdown menu, but I am encountering an issue where the items of the dropdown are overlapping. Despite my efforts to adjust the CSS classes, I have not been successful in fixing this problem.

Additionally, I have tried modifying the display settings for the links with no success. Below is the code snippet that I have written:

<style>
#menu
{
   margin:0;
   font-size: 30px;
   border-bottom: 1px solid;
   text-align: center;
}

#menu a
{
   color:#900;
   text-decoration:none;
}

#menu .subitem a{
   display: block;
   padding: 12px 16px;
   z-index: 1;
  background-color: #f1f1f1;
  border-bottom: 1px solid;
}

#menu a:hover
{
   text-decoration:underline;
}

.item{
   position: relative;
   display: inline-block;
   border-right: 0.5px solid;
   padding-right: 30px;
   padding-left: 30px;
}

.subitem{
  display: none;
  position: absolute;
  background-color: #f1f1f1;
  min-width: 160px;
  left: 0;
  z-index: 1;
}

#menu .item:hover .subitem{
    display: block;
}
</style>
<div id="navWrapper">
      <ul id="menu">
         <li class="item"><a href="#">Small Things</a>
            <ul class="submenu">
               <li class="subitem"><a href="#">Gnomes</a></li>
               <li class="subitem"><a href="#">Fairies</a></li>
               <li class="subitem"><a href="#">Elves</a></li>
               <li class="subitem"><a href="#">Leprechauns</a></li>
            </ul>
         </li>
         <li class="item"><a href="#">Big Things</a>
            <ul class="submenu">
               <li class="subitem"><a href="#">Loch Ness Monster</a></li>
               <li class="subitem"><a href="#">Ogres</a></li>
               <li class="subitem"><a href="#">Giants</a></li>
               <li class="subitem"><a href="#">Dragons</a></li>
            </ul>
         </li>

      </ul>
  </div>

I am aiming to achieve the desired display of each item when hovering with the mouse as shown in this image.

Answer №1

You mixed up your .submenu and .subitem:

#menu
{
   margin:0;
   font-size: 30px;
   border-bottom: 1px solid;
   text-align: center;
}

#menu a
{
   color:#900;
   text-decoration:none;
}

#menu .subitem a{
  display: block;
  padding: 12px 16px;
  z-index: 1;
  background-color: #f1f1f1;
  border-bottom: 1px solid;
}

#menu a:hover
{
   text-decoration:underline;
}

.item{
   position: relative;
   display: inline-block;
   border-right: 0.5px solid;
   padding-right: 30px;
   padding-left: 30px;
}

.subitem {
  /* display: none; <- remove that */
  /* position: absolute; <- remove that, or all subitems will be in top left corner */
  background-color: #f1f1f1;
  min-width: 160px;
  left: 0;
  z-index: 1;
}

.submenu {
  position: absolute; /* <- place it here */
  display: none; /* <- place it here */
  list-style-type: none;
  left: -40px;
  top: 30px;
}

#menu .item:hover .submenu {
  display: block;
}
<div id="navWrapper">
      <ul id="menu">
      
         <li class="item"><a href="#">Small Things</a>
            <ul class="submenu">
               <li class="subitem"><a href="#">Gnomes</a></li>
               <li class="subitem"><a href="#">Fairies</a></li>
               <li class="subitem"><a href="#">Elves</a></li>
               <li class="subitem"><a href="#">Leprechauns</a></li>
            </ul>
         </li>
         
         <li class="item"><a href="#">Big Things</a>
            <ul class="submenu">
               <li class="subitem"><a href="#">Loch Ness Monster</a></li>
               <li class="subitem"><a href="#">Ogres</a></li>
               <li class="subitem"><a href="#">Giants</a></li>
               <li class="subitem"><a href="#">Dragons</a></li>
            </ul>
         </li>

      </ul>
  </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

Angular 6 - implementing a dynamic carousel with bootstrap styling

I am currently working on a carousel using bootstrap4 where the images are sourced from an array. However, I am facing an issue where the first element must have the active class. <div id="carouselExampleFade" class="carousel slide carousel-fade" dat ...

What is the best way to choose $(this) within a JavaScript expression inside a template literal?

Is it possible to use template literals in the append method and get the index of the row generated? I understand that calling "this" inside the function selects the specified selector passed as an argument. $(document).on('click', '.ad ...

What is a method for capturing the value of a nested input element without requiring its ID to be

Currently, I am facing a challenge in selecting the value of an input box from a user-generated ordered list of text boxes and logging its value to the console. It seems like I cannot find a way to select the value of a child's child element when the ...

passing a javascript variable to html

I am facing an issue with two files, filter.html and filter.js. The file filter.html contains a div with the id "test", while the file filter.js has a variable named "finishedHTML." My objective is to inject the content of "finishedHTML" into the test div ...

Is there a way to resolve issues with window.open() on Heroku platform?

I've been working on hosting a webpage on Heroku using Node.js. Instead of using the php method, I opted to go with Node and it's been going smoothly so far. However, I've run into a small issue. Here's what my Procfile looks like: web ...

Guide to sending an HTML document containing images using the express framework

Is there a way to send an HTML file along with images using express? I have the following code that handles sending the initial page (index.html) to users. However, this page contains elements such as images and css files which are not being transferred p ...

Discover the magic of gradients in tooltips with Bootstrap 5!

I recently encountered some challenges when attempting to apply a gradient color to bootstrap 5 tooltips CSS: .tooltip .tooltip-arrow::before { position: absolute; content: ""; border-color: transparent; border-style: solid; } .bs-toolt ...

Retrieve information from specific dates by using a datepicker tool

Hey there, I'm trying to implement a datepicker calendar that allows me to select two dates and then click a button to display all the data between those dates. Here is my code snippet... <?php include_once 'header.php'; $con = mysqli_ ...

Determine with jQuery whether the img src attribute is null

My HTML structure is as follows: <div class="previewWrapper" id="thumbPreview3"> <div class="previewContainer"> <img src="" class="photoPreview" data-width="" data-height=""><span>3</span> </div> </div> ...

Visualization of XML Datamarkup

I am facing an issue with a function that generates XML from a source. Everything works perfectly except for when certain fields are too long, causing the table to stretch and mess up the website formatting. Is there a way to automatically insert line brea ...

What is the best way to generate a personalized error message when an HTML5 required input pattern fails to meet the criteria?

I am facing an issue with the following code snippet: <input required pattern=".{6,}" class="big medium-margin" name="Password" placeholder="Password" size="25" type="password" /> After entering just one character, I receive a message that says: " ...

Having trouble with enabling HTML5 mode to true on an Angular frontend and Laravel backend

I successfully removed the "#!" from my website URL and everything is working perfectly. The only issue I am facing is that when I try to reload a sub URL other than the home page, it shows a "page not found" error. However, I am able to access the same s ...

Remove the pop-up using its unique identifier, element, or style class

I recently launched a free hosting site, but I'm encountering an issue where an ad for the site keeps appearing upon loading. I need to find a way to remove the specific rows that contain this ad. Specifically, I want to delete the ****BOLD**** rows, ...

How can I use jQuery to locate all elements that match a specific style within the DOM?

Similar Question: How can I target hidden elements? Selecting multiple elements with CSS display:none property <div class="container"> <p style="display:none">I am hidden</p> <p>I am visible</p> <p>I am also ...

Combining two XPaths into a single XPath can be achieved by using various

HTML <li class="wdappchrome-ai" data-automation-id="searchInputAutoCompleteResult" tabindex="-2" aria-posinset="1" aria-setsize="3"> <span data-automation-id="searchInputAutoCompleteResultFullText"> <span style="font-weight:500"> ...

The HTML table fails to refresh after an Ajax request has been made

I am currently utilizing Ajax to delete a row from the Roles table. The functionality allows the user to add and delete roles using a link for each row. While the deletion process works properly and removes the row from the database, the table does not get ...

Launch in a new window using JavaScript

Check out my interactive map here. Currently, when I click on different sections of the map, the target page opens in the same window. However, I would like it to open in a new window instead. <iframe src="http://bluewingholidays.com/map/map.html ...

Trouble with jQuery on click function, no actions triggered

I am having trouble with this jQuery function that is supposed to post the value of a variable to a PHP page and display it in the correct status class. I have included the necessary jQuery file, but for some reason, nothing is happening. Any assistance w ...

When utilizing jQuery to add a <li> element, it suddenly vanishes

? http://jsfiddle.net/AGinther/Ysq4a/ I'm encountering an issue where, upon submitting input, a list item should be created with the content from the text field. Strangely, it briefly appears on my website but not on the fiddle, and no text is appen ...

Implement a feature in Bootstrap Vue Timepicker that automatically resets the minutes to 00 whenever the user selects the hours

When a user opens the timepicker, both hours and minutes will be blank. When they choose the hours, the minutes should automatically be set to 00. Thank you for your help. <b-form-timepicker v-model="meditation.start.time" ...