The background appears after the drop down menu text

I created a menu with a drop-down effect using CSS3 transitions. However, my issue is that the text is visible before the background appears, which goes against the intended design.

Here is a link to my JSFiddle.

HTML:

<nav>
    <ul>
        <li>Home</li>
        <li>Parent Link
            <ul>
                <li>Child Link</li>
                <li>Child Link</li>
                <li>Parent Link
                    <ul>
                        <li>Child Link</li>
                        <li>Child Link</li>
                        <li>Child Link</li>
                        <li>Child Link</li>
                        <li>Child Link</li>
                    </ul>
                </li>
            </ul>
        </li>
        <li>About</li>
        <li>Contact</li>
    </ul>
</nav>

CSS:

    nav {
        position: fixed;
        top: 0;
        width: 100%;
        height: 50px;
        background: #30a0ff;
        z-index: 2;
        box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.3);
}

nav > ul {
        position: relative;
    margin: 0 auto;
    padding: 0;
    width: 100%;
    list-style: none;
    text-align: center;
}

nav > ul > li {
    position: relative; 
    display: inline;
    padding: 12px 20px;
    line-height: 50px;
    font-size: 22px;
    color: #fff;
    cursor: pointer;
}

nav > ul > li:last-child {
    margin: 0 -20px 0 0;
}

nav ul li {
    -webkit-transition: all 0.2s ease-in-out;
    -moz-transition: all 0.2s ease-in-out;
    -ms-transition: all 0.2s ease-in-out;
    -o-transition: all 0.2s ease-in-out;
    transition: all 0.2s ease-in-out;
}

nav ul li:hover {
    background-color: #0f71c4;
}

nav > ul > li > ul {
    position: absolute;
    top: 50px;
    left: 0;
    height: 0;
    padding: 0;
    list-style: none;
    line-height: 20px;
    font-size: 17px;
    background-color: #30a0ff;
    overflow: hidden;
}

nav > ul > li:hover > ul {
    min-height: 110px;
    overflow: visible;
}

nav > ul > li > ul > li:first-child {
    padding: 15px 20px 5px 20px;
}

nav > ul > li > ul > li:last-child {
    padding: 5px 20px 15px 20px;
}

nav > ul > li > ul > li {
    position: relative;
    padding: 5px 20px;
    min-width: 150px;
    text-align: left;
}

nav ul li ul {
    box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.3);
    -webkit-transition: all 0.3s ease-in-out;
    -moz-transition: all 0.3s ease-in-out;
    -ms-transition: all 0.3s ease-in-out;
    -o-transition: all 0.3s ease-in-out;
    transition: all 0.3s ease-in-out;
}

nav > ul > li > ul > li > ul {
    position: absolute;
    left: 190px;
    top: 0;
    padding: 0;
    width: 0;
    list-style: none;
    font-size: 16px;
    background-color: #30a0ff;
    overflow: hidden;
}

nav > ul > li > ul > li:hover > ul {
    min-width: 150px;
}

nav > ul > li > ul > li > ul > li {
    position: relative;
    padding: 5px 20px;
    min-width: 150px;
}

nav > ul > li > ul > li > ul > li:first-child {
    padding: 15px 20px 5px 20px;
}

nav > ul > li > ul > li > ul > li:last-child {
    padding: 5px 20px 15px 20px;
}

Answer №1

I made a quick adjustment by adding opacity to the current CSS:

Check out the updated code on jsfiddle:

http://jsfiddle.net/r9Dyq/2/

Here is the modified CSS:

nav > ul > li > ul {
    position: absolute;
    top: 50px;
    left: 0;
    height: 0;
    padding: 0;
    list-style: none;
    line-height: 20px;
    font-size: 17px;
    background-color: #30a0ff;
    overflow: hidden;
    opacity:0; /*opacity added here */
}

nav > ul > li:hover > ul {
    min-height: 110px;
    overflow: visible;
    opacity:1; /*opacity added here */
}

Answer №2

Make sure not to modify the overflow attribute:

nav > ul > li:hover > ul {
  min-height: 110px;
  /*overflow: visible; Exclude this*/
}

View the demo at http://jsfiddle.net/r9Dyq/1/

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

Different "criteria" for CSS wildcard selectors using Selenium

There are several CSS webelements on my page with ids in the format: cell_[number]-button_[number] I am attempting to target ALL of these elements by using Selenium to locate all elements that begin with cell and include button: var elements = Util.driver ...

Issue with Angular table display cell overloading(produces excessive rendering of cells)

In my project, I am working with 3 arrays of data - DATA_CENT, DATA_NORTH, and DATA_WEST. Each of these arrays contains another array called data, which I need to extract and display in a table format. For each new column, I create a new table and then po ...

The blur effect isn't functional on the Firefox internet browser

When using the blur filter in my React application, everything works fine in Google Chrome and Microsoft Edge. However, I encountered an issue when testing it in Mozilla Firefox. Despite checking mozilla.org for solutions, I couldn't find anything spe ...

The sticky position is malfunctioning even when there is no parent element with the overflow hidden property

// observer for feature section let featuresSection = document.querySelector('#featuresSection'); let callbackFeature = (items) => { items.forEach((item) => { if (item.isIntersecting) { item.target.classList.add("in ...

The element's position remains unchanged after the .click re-event in the function

Welcome to my first attempt at using jQuery! Please bear with me as I navigate through this learning process. Here's the challenge: I have a series of elements in my HTML. <div class="garden"> <div class="point left">&#9668;</d ...

jQuery will not carry out the initial trigger action more than once

I've successfully implemented a feature where clicking on one of the 3 divs causes the main container to slide half away by 600px and reveal a new container with additional options. However, I'm facing an issue where after closing the new content ...

Display the HTML content retrieved from the SailsJS Controller

Exploring the world of SailsJS, I am on a mission to save HTML content in a database, retrieve it, and display it as rendered HTML. To achieve this goal, I have set up a sails model and a controller. This is what my model looks like: attributes: { ht ...

Introducing an alternative solution for handling tasks linked to the completion of CSS3 animations

In order to incorporate smooth CSS3 animations into my website, I have implemented the animate.css library created by Dan Eden. One particular scenario involves a loading screen that features a fade-out animation. It is crucial for this animation to comple ...

Closing the Bootstrap Dropdown Menu

I have a dropdown menu in my bootstrap project. I am looking for a way to make the menu close when I click on one of the menu items, without refreshing the page. The links function like an ajax request model, ensuring that the page does not reload. <l ...

In making reference to a particular subpage within a parent page

My website is designed with all inner pages linked to one master file. I'm looking to change the title font size on just one specific page, without affecting the rest of the pages that use the master file. Is there a way to target a specific page titl ...

Svelte's feature prevents users from inputting on Mapbox

My goal is to prevent user input when the variable cssDisableUserInput is set to true. Here's what I have within my main tags: <div id=userinput disabled={cssDisableUserInput}> <div id="map"> </div> Within my CSS, I&a ...

What is the best way to add a list to a JSON array?

I'm interested in learning how to create a loop using for each and for both methods. I want to access the id "list" in order to append li elements. HTML <div id="list"> <ul> <li>Mainland China</li> ...

Learn how to retrieve data using the $.ajax() function in jQuery and effectively showcase it on your HTML page

Can someone assist me with extracting data from https://jsonplaceholder.typicode.com/? Below is the AJAX call I'm using: $.ajax({ url: root + '/posts/', data: { userId: 1 }, type: "GET", dataType: "json", success: function(data) { ...

What is the best way to create a clickable button link using PHP echo?

Whenever I click the button, it always redirects to just story.php, ignoring all other details. I attempted using JavaScript but I found that utilizing form action is the closest method for me to accomplish this: <form action='./story.php?u=$id&a ...

Why is this dropdown list extending beyond the window?

Why is my dropdown list extending beyond the window? Despite trying to change the position of the dropdown list elements to fixed and top:0px, I am still facing this issue! I am unable to figure out why the list is going off the page. Your help in solvin ...

JavaScript: A guide on sending an uploaded email to a web service in byte array format

Scenario: My website is built using EXTJS6. I have a web service that requires the uploaded email to be sent in byte array format. Inquiry: What is the process for converting a .msg file to a byte array using JS (or EXTJS)? Can we treat it as a simple bin ...

Alterations to Firefox's placeholder color

Surprisingly, this code didn't work in Firefox (give it a try on Chrome and Firefox: http://jsfiddle.net/YzkSx/): <!doctype html> <html> <head> <title>Placeholder demo</title> <style type="text/css"> ...

accommodating multiple background images in CSS

I am currently working on a WordPress website using the Twenty Twelve theme. On one of the pages, I am trying to incorporate three background images - one at the top, the next one right below the top image, and the third one at the very bottom... Is there ...

Encountering a tIDENTIFIER syntax error while trying to include a button_tag in Rails

Currently, I am in the process of developing a rails application and my aim is to incorporate a button that executes a javascript onclick function. The code snippet I am using for this purpose is: <%= button_tag "Action" type: "button", onclick: "test( ...

Talwind Flexbox Grid Design

Currently, I am exploring the world of website layout creation using Tailwind Flexbox Grids as I believe it can add significant value. However, I have encountered some queries: How does one go about constructing a layout like this? Referencing this speci ...