What are some solutions to resolve the animation issue with CSS dropdown lists?

I am facing an issue with the animation in my dropdown list. The animation is only applying to the text within the ul list instead of the entire list item blocks.

Here is how it should function

This link contains the incorrect code

li:hover > ul.dropdown-content a:nth-child(1) {
    animation-name: menu1;
    animation-duration: 300ms;
    animation-delay: 0ms;
    animation-timing-function: ease-in-out;
    animation-fill-mode: forwards;
}

li:hover > ul.dropdown-content a:nth-child(2) {
    animation-name: menu1;
    animation-duration: 300ms;
    animation-delay: 50ms;
    animation-timing-function: ease-in-out;
    animation-fill-mode: forwards;
}

li:hover > ul.dropdown-content a:nth-child(3) {
    animation-name: menu1;
    animation-duration: 300ms;
    animation-delay: 100ms;
    animation-timing-function: ease-in-out;
    animation-fill-mode: forwards;
}

@keyframes menu1 {
    0% {
        opacity: 0;
        transform: rotateY(-90deg) translateY(30px);
    }
    80% {
        transform: rotateY(10deg);
    }
    100% {
        opacity: 1;
        transform: rotateY(0deg) translateY(0px);
    }

Answer №1

This issue arises from the conflicting styles applied to the ul element and its child elements. The background of the ul is set to be opaque while the child element has a transparent background, causing the animation to function correctly but remain invisible. To resolve this problem, you need to remove the background and box shadow properties from the ul:

.dropdown-content {
    ..
    background-color: transparent;
    box-shadow: none;
    overflow: visible; /* to display the box-shadow of its children */
    ...
}

Subsequently, apply these styles to the inner elements:

.dropdown-content a {
    color: black;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    text-align: center;
    background: #fff;
    box-shadow: 0px 5px 8px 0px rgba(0, 0, 0, 0.3);
}

Complete code example provided below:

// CSS code goes here
// Example styling for ul, li, a, dropdown content etc.
// Include relevant CSS snippets as needed
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul id='nav_bar'>
  // Navigation list items go here
  // Include dropdown menus if required

<div class='div' style="z-index:1;padding:20px;;background-color:#1abc9c;height:1500px;">
  // Content within the div container
  <p>Sample text goes here</p>

</div>

Answer №2

There is no need to add a background or box-shadow to the .dropdown-content element

.dropdown-content {
  display: none;
  position: absolute;
  background-color: transparent;
  min-width: 100px;
  box-shadow: unset;
}

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

Using jQuery and Perl to create a dynamic progress bar that is based on the current state of a "pipeline file" and utilizes AJAX

I'm looking to create a small pipeline that enables users to select a file and run multiple scripts using it as an input. Some of these scripts may take several minutes to complete (time depends on the file's size), so I want to display a progres ...

Is there a way to retrieve the text of li elements without assigning them IDs?

I have a list of names with four items inside it. My goal is to display the text of the selected name while hiding the others. Only one name should be visible at a time on the page. <ul id="names"> <li>John</li> <li>Alex</ ...

The TypeScript error code TS2345 indicates that the argument type 'JQueryXHR' cannot be assigned to the parameter type 'Promise<any>'

In a coding tutorial, an example code snippet demonstrates how to execute a JQuery getJSON() call and then transform the result into a Promise, which is later converted into an Observable. /// <reference path="../typings/tsd.d.ts" /> import { Compo ...

Activate CSS animation by clicking on a checkbox located within a fieldset

When a checkbox is checked, I want to activate an animation. Here is the HTML code I am using: <div data-role="fieldcontain" > <fieldset data-role="controlgroup" data-type="horizontal"> <input type="checkbox" class="mediaCheckbo ...

Selecting a variety of shapes from a painting

Within my canvas, there are various shapes like ovals, triangles, and squares. I am curious to know if it is possible to obtain a reference to one of these objects and animate it whenever a specific event occurs. Appreciate your attention to this query. I ...

Is it possible on a file upload page with html/php to enable users to select multiple files for upload without replacing the previously selected ones?

I have successfully implemented a form that allows users to upload multiple files, but I am facing an issue. The problem arises when a user selects a file, clicks 'open', and then decides to select another file. Upon clicking 'open' fo ...

Applying CSS styles to a shadow DOM element will not produce the desired visual

I'm encountering an issue while attempting to apply CSS to an element within a shadow-root by adding a class to it. In my Angular component, I have the following code: CSS .test { border: 1px solid red; } TS document.getElementById('my-div&a ...

An alternative method for adjusting the width of text input fields in CSS without using

Is there a CSS alternative to the calc function that can be used for older browsers (such as the default Android browser) in order to dynamically set the width of input text fields while leaving space on the right for a submit button? This is my current C ...

Obtaining the identifier of a list element from an external HTML document utilizing jQuery through AJAX

I have a separate HTML file that only consists of an unordered list with several list elements listed below: <ul> <li id="list-1"></li> <li id="list-2"></li> <li id="list-3"></li> <li id="list-4 ...

Checking for duplicate clicks on an element using jQuery

Is there a way to determine if the user is interacting with the same div element? I attempted the following code snippet without achieving the desired outcome: _oldthis = null; var _this = $(this); if(_oldthis == _this) { alert(&apo ...

Choosing Between HTML Entities and Unicode Code Points

Forgive me if this is a basic question, but I have been contemplating it and cannot seem to find a clear answer. When coding a special character for your website, should you use HTML Entity Decimal, HTML Entity Hexadecimal, or Unicode Code Point? What are ...

Having trouble with a dropdown menu that allows for multi-select options?

var expanded = false; function showCheckboxes() { var checkboxes = document.getElementById("checkboxes"); if (!expanded) { checkboxes.style.display = "block"; expanded = true; } else { checkboxes.style.display = "none"; expanded = fa ...

Currently, I am attempting to figure out the Xpath or CSS necessary to locate and interact with an Add

Struggling to pinpoint the Add button on our website that I'm currently automating using Python and Webdriver. The Xpath provided by Selenium IDE is as follows: adminAdd_button = driver.find_element_by_xpath("//button[@type='button'])[33]") ...

Display the vertical scroll bar of the page when the mouse hovers over it

Struggling to reveal the main page scrollbar upon hover? While working on my portfolio, I hid the page scrollbar. Trying to display the scrollbar when hovering over the main container. Below is a link to my portfolio page and corresponding code. Any assis ...

The typeface displayed is Rubik Light Font instead of the regular Rubik font

I am currently working on incorporating the Rubik Font into my project: <link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> < ...

Incorporating HTML files into JavaScript files

I have a text.html file located at C:\Users\project\text.html and I am looking to incorporate it into a .js testing file. My goal is to import the HTML file into one of my testing functions in order to test HTML elements. When I embed the h ...

Enable a function to be triggered when clicking on an entire div

In my code, I have set an eventHandler on the document itself that targets a specific element with an id. This targeted element is a div containing some content. The eventHandler is triggered by a 'click' action on the document. However, I have e ...

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 ...

Closing the fancybox after a form is submitted in ASP.NET MVC

I am facing an issue with my fancybox popup that contains a form. When the form is submitted, it redirects to the view and displays in full page mode. My goal is to have the form submitted within the popup itself and then close the fancy box. Below is th ...

Error: Papa is not defined. The file was loaded from the CDN in the header section

I have integrated the cdn hosted lib for PapaParse in my HTML header. However, when I execute my JavaScript file and it reaches the function where I call Papa.unparse(data); It throws an error stating that Papa is undefined. This has left me puzzled as I h ...