The dropdown menu in CSS is displaying only the final item on the list

Can anyone help me with my drop-down menu issue? It's only displaying the last items and I suspect there is something wrong with my CSS. Here are the details:

HTML Code:

<div class="menuBar">
    <nav class="Menu"> 
    <ul class="main">
    <li><a href="http://www.lombardisonthebay.com/" class="active">Home</a></li>
    <li><a href="wedding.html">Weddings</a>
        <ul>
        <li><a href="wedding-gallery.html">Gallery</a></li>
        <li><a href="testimonials.html">Testimonials</a></li>
        </ul>
    </li>
    <li><a href="restaurant.html">Restaurant</a>
        <ul>
        <li><a href="restaurant-gallery.html">Gallery</a></li>
        </ul>
    </li>
    <li><a href="social.html">Special Occasions</a></li>
    <li><a href="corporate.html">Corporate</a></li>
    <li><a href="upcoming.html">Upcoming Events</a></li>
    <li><a href="contact.html">Contact Us</a></li>
    <li><a href="locations.html">Our Locations</a></li>
    </ul>
    </nav>
 </div>

CSS Code:

nav.Menu {
    text-align: center;
    margin-top: 14px;
}

nav.Menu .main li {
    display: inline-block;
    margin-right: -4px;
    position: relative;
    padding: 5px 20px;
    cursor: pointer;
}

nav.Menu .main li ul li {
    padding: 0;
    position: absolute;
    top: 48px;
    left: 0;
    width: 150px;
    display: none;
    opacity: 0;
    visibility: hidden;
}

nav.Menu .main li ul li { 
    background: #83562c; 
    display: block; 
    color: #fff;
    margin-top: -2px;
    z-index: 1000 !important;
}

nav.Menu .main li:hover ul li { 
    background: #83562c; 
}

nav.Menu .main li:hover ul li {
    display: block;
    opacity: 1;
    visibility: visible;
    z-index:99;
}

nav.Menu a {
    color: #fff;
    font: bold 13px/42px Arial, Helvetica, sans-serif;
    padding: 0 10px;
    text-align: center;
}
nav.Menu a:hover    { 
    color: #eacc90;
}

Answer №1

Huangism makes a valid point about the issue caused by using position:absolute in your CSS, which is breaking the dropdown functionality. I have revamped the CSS code and provided it in this updated JSFiddle, although it may still be considered hackish.

If you're looking for more information on creating dropdown menus, I suggest checking out these resources:

Answer №2

This situation drove me to the brink of desperation, but with a clever workaround, setting position:absolute actually worked! Check out the solution here. I adapted this technique from this source.

.navmenu ul li ul {
  visibility: hidden;
  opacity: 0;
  position: absolute;
  transition: all 1s ease;
  margin-left: 142px;
  margin-top: -30px;
}

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

Issue with Audio TAG functionality in Internet Explorer 9

I am facing an issue with my jQuery code that generates an audio tag. The code works perfectly in Firefox and Chrome, but it is not functioning properly in IE9. Here is the code snippet: $(document).ready(function () { var source = "/TTS.aspx?tts=" + ...

Switch up div containers with JavaScript based on the set array order of elements?

As I work on creating a list that calculates the sum of selected numbers, I encountered an issue with rearranging the items. Despite successful functionalities like adding images with names, changing languages, and performing calculations, the page keeps r ...

Receiving time slots on a bootstrap schedule

I recently developed a calendar using Bootstrap that allows users to select a start date and automatically sets the end date within a 7-day range from the chosen start date. However, I am facing a challenge in enabling users to also pick minutes along with ...

How can I incorporate a transition into my modal with JavaScript in CSS?

I've recently started learning CSS and while I've come across similar topics, none have provided the solution to my specific problem. After spending 2 hours experimenting with various CSS properties like hidden, transition, and display, I am now ...

What is the best way to create responsive radio buttons on top of an image?

I have a photograph of the beautiful Hawaiian islands, and I've positioned 8 radio buttons using absolute positioning. However, when I inspect the image with the radio buttons on Chrome, I notice that they are not responsive and do not stay in their c ...

How to display HTML content in a UIWebView on iOS devices

When loading html content in a UIWebView on an iPhone6, I encountered an issue where actionable buttons triggered a pop-up in the middle of the content. However, since the content spanned approximately 6-7 pages, the user was unable to see the pop-up as it ...

The controller and node js request associated are invisible to my HTML page

Here is my HTML code. I have just created a unique controller for a specific part of the code. <div class="mdl-grid" ng-controller="ValueController"> <div class="mdl-card mdl-shadow--4dp mdl-cell--12-col"> <div class ...

Mastering JavaScript: Techniques for Selecting Multiple Values in a Dropdown Menu

I have a code that works perfectly, but the issue arises when I click on the add button and a new select option is added with a value instead of an id. How can I pass the Id to option.value = array[i]; ? var array = ["PACKING & LOADING","BAG GODOWN", ...

The autocomplete selection box is not appearing correctly

I am attempting to implement the jquery-ui autocomplete combobox in a .Net Core 2.2 web application, but I seem to be encountering a CSS issue. Here is how it currently appears: https://i.sstatic.net/wXaBg.png In addition to the jquery-ui CSS, I am also u ...

Replacing defined WordPress CSS styles

I was considering posting this query on the Wordpress Stack Exchange platform, but it's more related to CSS than Wordpress. Unless I need to delve into the CSS files of a plugin to customize the styles, should I go there to ask this question? I am t ...

Tips for preventing the appearance of two horizontal scroll bars on Firefox

Greetings, I am having an issue with double horizontal scroll bars appearing in Firefox but not in Internet Explorer. When the content exceeds a certain limit, these scroll bars show up. Can someone please advise me on how to resolve this problem? Is ther ...

Choosing "grandoffspring"

I have a complex inquiry! Let's examine three potential scenarios Situation 1 <div class="entry-content"> <p><a href="#"><img src="#"></a></p> </div> Situation 2 <div class="entry-content"> &l ...

Troubles with concealing dropdown menu when hovering

I have noticed that this issue has been raised before, but none of the solutions provided seem to fix my problem specifically. The submenu in my menu is not functioning as intended. It should be displayed when hovered over and hidden when not being hovere ...

Update the color of the Navigation Div once it has moved past a certain div

I am trying to update the color of my navbar-toggle from white to black or black to white. The issue arises when it reaches a specific div with a class like 'white' or 'black'; the color changes as soon as the scroll starts. var stick ...

How can we apply a hover effect to combine two rows in a table as one using CSS?

I'm having trouble figuring out how to highlight every two rows in a table as one when hovering over the current row. For example, if I hover on row 2, rows 2 and 3 should be highlighted. Then when I move to row 4, rows 4 and 5 should be highlighted, ...

Is the "position: sticky" feature functioning correctly, or is there a slight vibrating or dancing effect when users scroll through the Ionic app? How can we eliminate this issue specifically on iOS

Looking for suggestions on this problem - the position sticky is functioning correctly, but there seems to be a slight vibration or dancing effect when users scroll in the Ionic app. Any ideas on how to eliminate this issue specifically on iOS devices? & ...

Trigger Form Submission When Checkbox is Modified

Here is the PHP code I am working with: I need to update a value in the database immediately when a checkbox is checked or unchecked. I am looking to accomplish this using either PHP or Javascript. <?php session_start(); include("head.php"); inclu ...

Column reverse flex-direction is functioning correctly, however, it is imperative that it does not automatically scroll to the bottom

I have a Flexbox set up where I need the contents to display in reverse order. Everything is working well, but the list has many items and the newest ones are appearing at the top. Currently, the Flexbox automatically scrolls to the bottom, but I want it t ...

What modifications can I make to my JavaScript code in order to enable clicking through an HTML list?

I'm facing an issue with getting my list to function properly. I want users to be able to navigate through the list by clicking on next and previous buttons, but for some reason, the code is not working as expected. When they click next, the next item ...

What could be causing my cross fade to not repeat as intended?

I created a basic background image cross fader using the code found at http://jsfiddle.net/jRDkm/2/. This code was inspired by . However, I'm encountering an issue where the slideshow only repeats once before fading to white. How can I modify the cod ...