Two keyframes are unable to function simultaneously

I am facing an issue with transitioning two divs, "hat" and "sock". The "hat" transition works as intended, but for some reason, the "sock" transition is not working. I have checked the properties and made sure they are set up in a similar way to "hat", yet it still does not work. I even attempted changing the @keyframe pageExitRight property from "right: 40" to "left: 40", but that did not resolve the problem.


body {
    background-color: white;
}
.box {

    /* TITLES OF CHOICES */

    position: relative;
    background-color: gainsboro;
    border-radius: 50%;
    width: 400px;
    height: 400px;
    display: inline-block;
    margin: 10%;
    transition: all 1s;
}
#hat {
    animation-name: pageExitLeft;
    animation-timing-function: ease-out;
    animation-duration: 2s;
    position: relative;

    background-image: url(hat.jpg);
    background-position: center;
}
#sock {
    animation-name: pageExitRight;
    animation-timing-function: ease-out;
    animation-duration: 2s;
    position: relative;

    background-image: url(sock.jpeg);
    background-position: center;
}
div.box:hover{

    /* CHANGE COLOR WHEN MOUSE HOVER */
    opacity: 0.5;
} 

@keyframes pageExitLeft {
    from { left: 40; opacity: 1 }
    to { left: -440; opacity: 0 }
}
@keyframes pageExitRight {
    from { right: 40; opacity: 1 }
    to { right: -440; opacity: 0 }
}




<html>
    <head>
        <link rel="stylesheet" href="main.css">
    </head>
    <body>
        <div class="box" id="hat" >hat</div>
        <div class="box" id="sock">sock</div>
    </body>
</html>

Answer №1

You've forgotten to include the units in your @keyframes declarations. You mention left: 40, right: 40, left: -440, right: -440, but it's important to specify what these numbers actually represent.

Consider revising your CSS with the following code snippet:


    body {
        background-color: white;
    }
    .box {

        /*   CHOICE SELECTION TITLES    */    

        position: relative;
        background-color: gainsboro;
        border-radius: 50%;
        width: 400px;
        height: 400px;
        display: inline-block;
        margin: 10%;
        transition: all 1s;
    }

    #hat {
        animation-name: pageExitLeft;
        animation-timing-function: ease-out;
        animation-duration: 2s;
        position: relative;
        background-image: url(hat.jpg);
        background-position: center;
    }

    #sock {
        animation-name: pageExitRight;
        animation-timing-function: ease-out;
        animation-duration: 2s;
        position: relative;
        background-image: url(sock.jpeg);
        background-position: center;
    }

    div.box:hover{

        /*   COLOR CHANGE ON MOUSE HOVER  */ 
        opacity: 0.5;
    } 

    @keyframes pageExitLeft {
        from  {left: 40px; opacity: 1}
        to    {left: -440px; opacity: 0}
    }

    @keyframes pageExitRight {
        from  {right: 40px; opacity: 1}
        to    {right: -440px; opacity: 0}
    }

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

The collapsible navigation bar vanishes when toggling in Bootstrap 4

My first time using Bootstrap 4, and I'm encountering a challenge that was much simpler in Bs3: I want the link items in my navbar to collapse into a hamburger menu when the screen size is xs. While the documentation and another answer touch on this, ...

Choosing the initial offspring of an element that do not share a common parent

My question might not be perfectly phrased, for which I apologize. Is there a CSS method to select only the first child of an element without affecting others that are not grouped under the same parent? For instance: <div class="parent"> <div ...

Exploring the theme color options in Angular Material

Despite extensive searching on SO and GitHub, I am seeking clarification: Is it impossible to access a theme color (or any other theme feature) in order to set a mat-card color? There is no way to retrieve a variable in scss. You cannot assign a class to ...

What is the best way to create a line break in a flex div container to ensure that overflowing items wrap onto the next line using

Using material-ui popper to display a list of avatars. Trying to arrange the avatars horizontally within the popper. <Popper style={{ display: 'flex', maxWidth: '200px', }}> <div style={{ marginRight: '20px' }}&g ...

Is there a way to deactivate a clickable div immediately after it has been clicked on?

I have been searching for a solution to this particular question on different platforms, including Stack Overflow. However, I am looking for an answer using pure JavaScript only, so please avoid jQuery solutions. In order to provide context, I have includ ...

Excessive indentation detected within the website's formatting

There seems to be an issue with the mobile version of the website, possibly related to flexbox, SVG, or width settings that are unclear to me. Inspecting with Devtools reveals indents from the SVG and text itself. Check out the website here My goal is to ...

The text stubbornly refusing to conform to a single line

I am currently experiencing an issue where the text inside the anchor tag is not adjusting to a single line. Below is my HTML code: <html> <head> <link rel="stylesheet" href="style5.css" type="text/css"> </head> ...

Navigating a mobile-friendly menu anytime!

I'm in the process of creating a responsive "hamburger" menu for mobile devices. The HTML code I have implemented is as follows... .menu_closed { color: red; } .menu_open { color: blue; } <script src="https://ajax.googleapis.com/ajax/libs/jq ...

Arranging individual spans within a div using CSS for perfect alignment

My current code looks like this: <div id='div_selectores' class='row_titulo '> <span class="label_selector" id="lbl_show"></span><span id="div_selector_show"></span> <br /> <span class ...

Fixed navigation menu at the top of the screen

Can anyone help me with my navbar issue? I want it to stay on top of the page, but there's a huge gap between the top of the page and the nav bar. I've tried running a JS file, but it doesn't seem to fix the problem. Any ideas on how to make ...

Tips for eliminating the default arrow on the HTML select tag?

I am currently utilizing vuejs along with tailwindcss and I am trying to figure out how to get rid of the default arrow from an HTML select element. Despite my attempts to remove it by using CSS properties like -moz-appearance, -webkit-appearance, -ms-appe ...

What is the easiest way to toggle the display of the hamburger menu in a basic grid or flex layout?

I have recently created a grid and flex-based menu. How can I make the hamburger menu function to show/hide the menu on click? Is there a way to achieve this without using JavaScript? Here is the current code snippet: .menu { display: grid; g ...

Unable to access account: HTML Javascript login issue

Problem with Login Code As a newcomer to HTML, CSS, and almost unknown in Javascript, I sought help from others to create a login code. The code was working fine earlier, but now it's not functioning as expected. Despite checking everything, I can&ap ...

Is it possible to eliminate the *:after effect for specific elements in my CSS?

I struggle with CSS, so I decided to use a library that includes the following CSS code: *, *:before, *:after { box-sizing: inherit ; } While this code works well for some views, it messes up others and is unnecessary for some. For instance, in this b ...

Could a complex, intricate clipping path be created using CSS 3?

Here is an example: Can this be achieved using only CSS? I wish to create two divs: A circle without any background or border. A div with a background. I aim to have point 1 clip the background from point 2. This will allow me to rotate the backgroun ...

What is the best way to use margin-top and margin-bottom in CSS?

Looking to perfectly center this modal in the middle of the screen with some margin all around. However, struggling to apply margin specifically to the top and bottom! export function Modal() { return ( <div className="fixed inset-0 z-[60] ...

Options for Printing HTML - Explore Different Techniques for Creating HTML Printouts and Weigh the Advantages and Disadvantages

As I work on maintaining an application, I am faced with the task of printing out a report. However, my curiosity extends beyond this assignment as I wonder about the various ways to format an HTML page for optimal printing results and the advantages and d ...

Close the Bootstrap burger menu after clicking on a scrollspy link

Is there a way to automatically collapse the Bootstrap burger menu when clicking on a scrollspy link? While browsing my website on a mobile device, the Bootstrap navigation menu switches to a burger icon. However, when you click on an internal link that l ...

The identical animation is experiencing delays in various directions

Having an issue with my image slider - when clicking on the previous image button, the animation takes longer compared to when clicking on the next image button, even though the animation duration is set to be the same for both. Any idea why this might be ...

Place background image in the center with a background color overlay

After browsing through this post on Stack Overflow, I managed to stretch my background image using CSS with the background-size: cover; property. However, I realized that this solution doesn't completely meet my needs. I'm dealing with an image ...