Could CSS transitions stack on top of each other?

My current approach involves using CSS to create sliding menus. With JavaScript, I simply apply a class to trigger the CSS animations. The menu consists of 4 columns with list items in desktop mode, but collapses into only headings in mobile mode. These headings are clickable to reveal the menu.

While my menu functions correctly overall, I've noticed that the animation for sliding down differs from sliding up. Sliding up appears slower and starts later, which is not the desired effect. I want both sliding down and sliding up to have the same smooth transition.

For reference, you can view my JSfiddle here: JSfiddle

HTML

<div class="site-footer">
    <div class="row">
        <div class="col-25p">
            <span class="footer-heading">Heading 1</span>
            <div>
                <ul>
                    <li><a href="#">Sub 1</a></li>
                    <li><a href="#">Sub 2</a></li>
                    <li><a href="#">Sub 3</a></li>
                    <li><a href="#">Sub 4</a></li>
                    <li><a href="#">Sub 5</a></li>
                </ul>
            </div>
        </div>
        <!-- Remaining HTML code remains unchanged -->
    </div>
</div>

SCSS

.site-footer {
font-size: 1.3rem;

.footer-heading {
    display: block;
    color: black;
    font-weight: bold;
    font-size: 18px;
    padding-top: 4px;

    /* Remaining SCSS code remains unchanged */
}

/* More SCSS code included for styling */

.col-25p{
  @media (min-width: 768px){
    float:left;
    width: 25%;
  }
}

JavaScript

$('.site-footer .footer-heading').click(function(){
        $(this).toggleClass('open');
    });

Answer №1

When animating the max-height property, it transitions from 0px to 500px and then back. However, if the divs being animated are smaller than 500px, this can cause a delay in the closing animation.

To address this issue, one solution is to dynamically set the max-height property of the elements using JavaScript.

Answer №2

Make sure to include & + div

transition:all 500ms ease;
transition-duration: 1s;
transition-timing-function: cubic-bezier(0.17, 0.04, 0.03, 0.94);

Give this a shot

.site-footer {
    font-size: 1.3rem;

    .footer-heading {
        display: block;
        color: black;
        font-weight: bold;
        font-size: 18px;
        padding-top: 4px;

        &:hover{
            cursor: pointer;

            @media (min-width: 768px){
                cursor: default;
            }
        }

        &::after {
            font-family: "FontAwesome";
            float: right;
            content: "\f078";
            transition:all 500ms ease;
            transition-duration: 1s;
            transition-timing-function: cubic-bezier(0.17, 0.04, 0.03, 0.94);

            @media (min-width: 768px){
                content: "";
            }
        }

        &.open{
            &::after{
                transform: rotate(180deg);
            }

            & + div{
               max-height:500px;
               transition:all 500ms ease;
               transition-property: all;
               transition-duration: 1s;
               transition-timing-function: cubic-bezier(0.17, 0.04, 0.03, 0.94);
            }
        }


        & + div {
            overflow-y: hidden;
            max-height: 0;
            transition-property: all 500ms ease;
            transition-duration: 0.3s;
            transition-timing-function: cubic-bezier(0.17, 0.04, 0.03, 0.94);

            @media (min-width: 768px){
                max-height: 500px;
            }
        }

    }

    ul {
        list-style: none;
        padding-left: 0px;

        li {
            padding-top: 4px;
            padding-bottom: 4px;

            a {
                color: black;
                text-decoration: none;

                &:hover {
                    text-decoration: underline;

                }
            }
        }
    }
}


.col-25p{
  @media (min-width: 768px){
    float:left;
    width: 25%;
  }
}

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

I am unable to move HTML data to PHP

Here is my HTML code: <form action="test.php" method="get> <input type="text" name="text" /> </form> And this is my PHP code: <html> <head> <title>Result</title> </head> <body style="background: ...

Adding custom fonts to DOMPDF: a step-by-step guide

First, I moved the dompdf library folder to /dompdf Next, I added a /fonts folder containing Roboto-Black.ttf Then, I created an index.php file <?php // Autoloader inclusion require_once 'dompdf/autoload.inc.php'; // Namespace reference ...

Imagine watching an image shrinking down and appearing in the center of the screen

I'm struggling with making the image smaller and centering it while keeping its original size. I'm using Bootstrap and need a solution for this issue. How can I make the image centered and shown in its original size? <div class="contain ...

Relocate the Bootstrap selector box form to align with the left side of the page

I have included the Bootstrap CDN in my project, and I am encountering an issue with a form that contains a dropdown box. The problem is that the legend tag is properly aligned to the left of the page, but the selector box is slightly indented towards th ...

Sending authorization codes to web pages

I have developed a user authentication system that generates an access token after successful login. The challenge I am facing is passing this token to different pages as a header parameter in order to grant access to those pages. module.exports.authen ...

How can I reduce the size of a Bootstrap 5 carousel that spans the entire screen?

As someone new to web development, I have found using bootstrap to be extremely helpful. However, I am currently struggling with creating a carousel for my website. My goal is to display some pictures in one corner of the page, but the carousel keeps str ...

Multiplication cannot be performed on operands of type 'NoneType'

Hello everyone, I am attempting to calculate the unit price and quantity from this table using the following model: class Marketers(models.Model): category =models.ForeignKey(Category, on_delete=models.CASCADE, null=True) name =models.CharField(max ...

Learn how to alter the website's overall appearance by changing the background or text color with a simple click on a color using Angular

Is there a way to dynamically change the background color or text color of the entire website when a user clicks on a color from one component to another? I know I need to use the Output decorator, but how can I implement this? style.component.html <di ...

The hover effect for a :before class is not functioning as intended

I have created a dropdown menu with a triangle at the top in this style: When the cursor hovers over only the triangle, it appears like this: However, when the cursor is over the div, the hover effect for both elements is activated as shown here: I am t ...

How come it functions with $scope but fails with `this`?

I am trying to figure out why my code only works with scripts 1 and 3, but not with script 2. I need this functionality for my project because I can't use $scope. Thank you!! <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.19 ...

Tips on Updating Array Value with jQuery

I have been working on using jQuery to edit array values. Here is my approach: From a modal, each time I click the "Add item" button, it pushes values to an array and appends the data to a table. var iteminfo = { "row": 'row' + cnt, "ma ...

Loading large content using jQuery's .html() method

After experimenting with the jQuery .html() function, I've noticed that it struggles to handle large amounts of text. You can see an example of this issue. Fortunately, a much simpler test case works perfectly fine. While I understand that including ...

Embed JavaScript within the Material-UI style components

I was hoping to incorporate some conditional logic within my MUI styles Currently, I am using inline styles which are functional <div className={classes.form} style={{alignItems: ((Code.length>10 || Description.length>100) ? 'start' : & ...

What is the best way to display a mySQL database in an HTML div table?

Showcasing the grades in a table format: username assignment weight mark a a1 10% 50% b a1 10% 60% Can this be achieved using PHP/HTML? <div class="a"> <div class="divTabl ...

Issue with the position of the search dropdown in HTML

When we click on the Dropdown option, it appears above the text instead of below. I have been trying to fix the positioning issue where the Dropdown shows up separately after clicking, but I have not been successful so far. Maybe you can offer some assist ...

Struggling to locate the distinctive XPath for the button

I am facing a situation where the XPath is non-unique and identifies 3 elements on the page that change positions upon refresh: <div class="col-xs-12 Hover"> <button data-testid="continueCheckoutButton" ng- class="continueDellMetricsC ...

Having trouble with Bootstrap dropdowns not opening when clicking with jQuery?

I am in the process of developing a table with multiple rows, each containing an "Options" button to display a dropdown context menu. To streamline the code, I am utilizing a single div to serve as a common markup for the context menu. The technologies I ...

Is the main content positioned below the sidebar on smaller screens?

In order to achieve a 250px col-2 sidebar with a col-10 main body that collapses into a top navbar and main content beneath it, my goal is set. However, I am facing an issue where the main content body goes underneath the sidebar when the screen size cha ...

Angular allows for the creation of a unique webpage layout featuring 6 divs

I am working on a project where I have an image of a car and I need to overlay 6 divs onto the image which can be selected with a mouse click. When a user clicks on one of the divs, it should change color. I've attempted using z-index, but it doesn&ap ...

JavaScript function to convert a string of characters into a readable time format

Is there a way to input a string in an 'input type="time"' field in my HTML code? <label class="item item-input"> <span class="input-label">Departure Time </span> <input type="time" ng-model="heur ...