Firefox failing to properly display CSS animations transitioning from behind other elements

Check out this simple example to see what I'm referring to.

HTML

<div class="main-container">
<div class="ht-tx1"></div>
<div class="headtest"></div>
<div class="ht-tx2"></div>
</div>

CSS

.main-container {
    width: 100%;
    height: 200px;
    margin: 250px 0 0 0;
    position: relative;
    background-color: yellow;
}

.headtest {
    font-family: 'quicksand', helvetica;
    background-color: #a2aba2;
    width: 100%;
    height: 200px;
    position: absolute;
    top: 0;
    right: 0;
}

.ht-tx1 {
    width: 100%;
    height: 20px;
     text-align: center;
     background-color: #000;
     animation: test-ani1 2s forwards;
     position: absolute;
     top: 0;
     right: 0;
}

.ht-tx2 {
    width: 100%;
    height: 20px;
    text-align: center;
    background-color: #000;
    animation: test-ani2 2s forwards;
    position: absolute;
    bottom: 0;
    right: 0;
}



@keyframes test-ani1 {

    100% {
        transform: translateY(-20px);
    }
}

@keyframes test-ani2 {

    100% {
        transform: translateY(20px);
    }
}

-

In Chrome, both black bars slide out perfectly - one from behind and the other in front. However, in Firefox, the bar transitioning from behind is not working correctly. It sometimes appears at the end of the animation duration without sliding properly.

I have tried various solutions like using -moz- and adjusting positioning with z-index, but nothing seems to fix the issue.

EDIT ----

While I appreciate workarounds, I am more interested in understanding the root cause of this issue. Does anyone have any insights?

Thank you!

Answer №1

Firefox seems to have some inconsistency when animating the transform property, and the reason for this is unclear at the moment. It's most likely a bug.

Here are two alternative solutions to achieve the same effect:

.main-container {
    width: 100%;
    height: 200px;
    margin: 50px 0 0 0;
    position: relative;
    background-color: yellow;
}

.headtest {
    font-family: 'quicksand', helvetica;
    background-color: #a2aba2;
    width: 100%;
    height: 200px;
    position: absolute;
    top: 0;
    right: 0;
}

.ht-tx1 {
    width: 100%;
    height: 20px;
     text-align: center;
     background-color: #000;
     animation: test-ani1 2s forwards;
     position: absolute;
     top: 0;
     right: 0;
}

.ht-tx2 {
    width: 100%;
    height: 20px;
    text-align: center;
    background-color: #000;
    animation: test-ani2 2s forwards;
    position: absolute;
    bottom: 0;
    right: 0;
}



@keyframes test-ani1 {
    0% {
        transform: translateY(-1px);
    }
    0.1% {
        transform: translateY(0px);
    }
    100% {
        transform: translateY(-20px);
    }
}

@keyframes test-ani2 {
    100% {
        transform: translateY(20px);
    }
}
<div class="main-container">
<div class="ht-tx1"></div>
<div class="headtest"></div>
<div class="ht-tx2"></div>
</div>

.main-container {
  width: 100%;
  height: 200px;
  margin: 50px 0 0 0;
  position: relative;
  background-color: yellow;
}

.headtest {
  font-family: 'quicksand', helvetica;
  background-color: #a2aba2;
  width: 100%;
  height: 200px;
  position: absolute;
  top: 0;
  right: 0;
}

.ht-tx1 {
  width: 100%;
  height: 20px;
  text-align: center;
  background-color: #000;
  animation: test-ani1 2s forwards;
  position: absolute;
  top: 0;
  right: 0;
}

.ht-tx2 {
  width: 100%;
  height: 0px;
  text-align: center;
  background-color: #000;
  animation: test-ani2 2s forwards;
  position: absolute;
  bottom: 0;
  right: 0;
}


@keyframes test-ani1 {
  100% {
    top: -20px;
  }
}

@keyframes test-ani2 {
  100% {
    height: 20px;
    bottom: -20px;
  }
}
<div class="main-container">
  <div class="ht-tx1"></div>
  <div class="headtest"></div>
  <div class="ht-tx2"></div>
</div>

Answer №2

The key to solving this issue lies in understanding the z-index property of your elements: if left unspecified, the elements stack on top of each other following the HTML document flow when their "position" is set to "absolute". In this case, "ht-txt1" is positioned beneath "headtest" while "ht-tx2" appears above it.

To fix this problem, both "ht-tx1" and "ht-tx2" should be assigned a "z-index" value of -1 so that they are hidden underneath "headtest".

For Firefox compatibility, it's important to add the -moz- prefix to your "transform" effect. You can refer to http://caniuse.com/#feat=transforms2d for more information.

Here's the CSS code snippet:

    .main-container {
        width: 100%;
        height: 200px;
        margin: 250px 0 0 0;
        position: relative;
        background-color: yellow;
    }

    .headtest {
        font-family: 'quicksand', helvetica;
        background-color: #a2aba2;
        width: 100%;
        height: 200px;
        position: absolute;
        top: 0;
        right: 0;
    }

    .ht-tx1 {
        width: 100%;
        height: 20px;
        text-align: center;
        background-color: #000;
        animation: test-ani1 2s forwards;
        position: absolute;
        top: 0;
        right: 0;
        z-index: -1;
    }

    .ht-tx2 {
        width: 100%;
        height: 20px;
        text-align: center;
        background-color: #000;
        animation: test-ani2 2s forwards;
        position: absolute;
        bottom: 0;
        right: 0;
        z-index: -1;
    }

    @keyframes test-ani1 {

        100% {
            -ms-transform: translateY(-20px);
            -webkit-transform: translateY(-20px);
            -moz-transform: translateY(-20px);
            transform: translateY(-20px);
        }
    }

    @keyframes test-ani2 {

        100% {
            -ms-transform: translateY(20px);
            -webkit-transform: translateY(20px);
            -moz-transform: translateY(20px);
            transform: translateY(20px);
        }
    }  

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

Determining the window height using jQuery when overflow is set to hidden

I've built a full screen web application that I don't want to scroll, so I used this code: $("body").css("overflow", "hidden"); However, after adding a resize listener: $(window).resize(function(){ console.log("Inner height: " + $(window). ...

Navigating through a Bootstrap slideshow with the help of directional arrows

Exploring bootstrap for the first time, I'm interested in creating a carousel gallery. Are there any templates or resources that can help in achieving this? I envision an image displayed at the top, with its description shown in a separate div below. ...

jQuery not getting desired response from AJAX GET request

I'm currently working on a project that involves displaying the member list of all users using AJAX get request. Everything seems to be functioning properly, but the content appended to my HTML is not responding to another jQuery script. Is there a w ...

Div refuses to change its size

This question has been resolved To achieve the desired layout, I adjusted the position of two children elements to 'absolute' since they will not change in size. I then repositioned the other children whose sizes remain constant to the top. Fina ...

Enhance your Android desktop applications with cutting-edge CSS frameworks

When developing normal web applications, many of us turn to CSS frameworks like Bootstrap. I have also come across some CSS frameworks tailored for mobile apps, such as PhoneGap. However, I am curious if there are any CSS frameworks specifically designed f ...

Displaying PHP content using JavaScript classes

I have a popup feature implemented in JavaScript and all the necessary scripts added to my HTML page. I am attempting to load a PHP page in the popup when the submit button of my form is clicked. The popup is functioning correctly for buttons like the one ...

Adding additional text within the paragraph will result in the images shifting backwards when utilizing flexbox

It seems like there might be something obvious that I'm missing here, but essentially my goal is to create a footer with 2 columns and 2 rows. In each column, there will be an icon (32x32) and 2 lines of text next to it. The issue I'm facing is ...

Next and previous buttons are missing in simple HTML design when using Owl carousel

https://i.sstatic.net/pdXfS.png My HTML design includes Owl carousel, which is functioning properly but not displaying the next and previous buttons. Even after adding buttons to my page manually, they are still not showing up. Interestingly, when I implem ...

Issue with CSS and JS Files in Subdomains

I have implemented the following rules in my .htaccess file: RewriteEngine on RewriteCond %{HTTP_HOST} !^www\. RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com RewriteRule ^(.*)$ index-merchant.php?id=%1 [L,NC,QSA] When I access trytry.domain.c ...

Divide a single image into several smaller images and enable clickable links on each separate image, similar to an interactive image map

Challenge: I am faced with the task of splitting a large image (1920px x 1080px) into smaller 40px by 40px images to be displayed on a webpage. These smaller images should come together seamlessly to recreate the original full-size image, with 48 images a ...

How can we seamlessly transition from adding a class to setting scrollTop on a particular div?

I have successfully implemented a jQuery script to change the background color of my navbar on scroll. Here's the code I used: jQuery(document).ready(function($) { $(window).scroll(function() { var scrollPos = $(window).scrollTop(), nav ...

When using Angular 8 with RxJs, triggering API calls on click events will automatically detach if the API server is offline

I have an Angular 8 application with a form containing a save button that triggers a call to a Spring Boot microservice using RxJs. I decided to test what would happen if the Rest API server were down. When the Rest API is running, clicking the button wor ...

Emblem pointing towards the header

Seeking advice for modifying arrow function: <script> $(window).scroll(function() { var pxFromBottom = 1300; if ($(window).scrollTop() + $(window).height() > $(document).height() - pxFromBottom) { $('#nagore').fa ...

Angular animation not firing on exit

I am encountering an issue with my tooltip component's animations. The ":enter" animation is working as expected, but the ":leave" animation never seems to trigger. For reference, here is a link to stackblitz: https://stackblitz.com/edit/building-too ...

Converting HTML to PDF in Flutter without using the flutter_html_to_pdf package for Flutter web compatibility

Is there a way to convert HTML content to PDF in Flutter that supports both mobile and web? I have the following HTML content: content: <p>sample text</p><p><b>sample text</b></p><p><i><b>sample text& ...

Unusual scrolling behavior in iOS 7 when using PhoneGap and jQuery Mobile

I am currently working on a simple app that includes a list of elements within a page. I am utilizing PhoneGap in conjunction with jQueryMobile for this project. After testing both the jQuery Mobile Listview and a custom list implementation, I have encount ...

Navigating through cards in HTML: A guide to filtering techniques

I'm currently in the process of developing a platform that enables users to browse through different profiles based on their first names. I've attempted to utilize bootstrap's "data-title" for searching purposes, but unfortunately, it's ...

Steps for dynamically changing the class of a dropdown when an option is selected:

Check out this code snippet : <select class="dd-select" name="UM_Status_Engraving" id="UM_Status_Engraving" onchange="colourFunction(this)"> <option class="dd-select" value="SELECT">SELECT</option> <option class="dd-ok" value= ...

Hiding the author, category, and date information from displaying on WordPress posts

After creating a Wordpress blog site and adding the category widget to the right sidebar as a drop down, I realized that I needed to customize its layout in terms of colors and design. However, I am struggling to find out how it can be done, which .php fil ...

Modifying the order of Vuetify CSS in webpack build process

While developing a web app using Vue (3.1.3) and Vuetify (1.3.8), everything appeared to be working fine initially. However, when I proceeded with the production build, I noticed that Vue was somehow changing the order of CSS. The issue specifically revol ...