Animate a div to show after another with CSS

Is there a way to display 3 divs consecutively using only CSS3 in a loop?

The sequence should be: first div without delay, followed by the second div, and then the third:

This is my attempt so far:

.text1 {
    animation-duration: 3s;
    animation-name: slidein;
    animation-iteration-count: infinite;
}

@keyframes slidein {
    0% { opacity: 0; }
    25%,75%  { opacity: 100%; }
    100% { opacity: 100%;}
}

.animate-delay-3 { animation-delay: 3s;}
.animate-delay-6 { animation-delay: 6s;}
<div id="container">
    <a href="#">
        <div id="header" class="header"></div>

        <div class="layer text1">
            <img src="div1.png" alt="">
        </div>
        <div class="layer text1 animate-delay-3">
            <img src="div2.png" alt="">
        </div>
        <div class="layer text1 animate-delay-6">
            <img src="div3.png" alt="">
        </div>

    </a>
</div>

Answer №1

Just a heads up, the value of 100% is not accurate for opacity; it should actually be a float between 0 and 1.

Another point to note is that we should initialize the opacity of every box to 0.

If I am understanding correctly, you want the animation to play just once, so set animation-iteration-count to 1.

Lastly, if you want the elements to remain visible after the animation completes, use animation-fill-mode: forwards.

Here is the updated code snippet:

.text1 {
        animation-duration: 3s;
        animation-name: slidein;
        animation-iteration-count: 1;
        opacity: 0;
        animation-fill-mode: forwards;  
    }

    @keyframes slidein {
        0% { opacity: 0; }
        25%,75%  { opacity: 1; }
        100% { opacity: 1;}
    }


    .animate-delay-3 { animation-delay: 3s;}
    .animate-delay-6 { animation-delay: 6s;}
<div id="container">
    <a href="#">
        <div id="header" class="header"></div>

        <div class="layer text1">
            <img src="http://lorempixel.com/g/80/80/" alt="">
        </div>
        <div class="layer text1 animate-delay-3">
            <img src="http://lorempixel.com/g/80/80/" alt="">
        </div>
        <div class="layer text1 animate-delay-6">
            <img src="http://lorempixel.com/g/80/80/" alt="">
        </div>

    </a>
</div>

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

svg xlink attribute not functioning properly when embedded as svg object within html

Within the SVG, I have multiple A elements linking to various pages. When the SVG is loaded into a browser as a standalone, the links function properly. However, when it is embedded as an object within an HTML page, the links do not work. It seems like th ...

Utilizing Jquery and Ajax to create a dynamic dropdown selection feature based on dependencies from a JSON file

Could you assist with the code snippet below? I have a form where each dropdown list depends on the selection above it. Based on the user's selection, the appropriate data should display in the subsequent dropdown list. I am trying to make dropdown l ...

The mouse coordinates do not align with the drawing of a rectangle on the canvas

I am having some issues with drawing a rectangle on mouse drag over the canvas that is overlayed on an HTML5 video JS player. The rectangle is being drawn, but it does not align correctly with the mouse coordinates. I suspect that the canvas, which is ove ...

Trouble with Selenium Webdriver executing Custom Ribbon Button

I encountered an issue while trying to click on a Custom Ribbon MSCRM2011 Button in an automation script I'm writing. Below is the HTML structure: <li id="contact|NoRelationship|Form|Mscrm.Form.contact.MainTab.ExportData" class="ms-cui-group" unse ...

Defining the limits for a JavaScript canvas game

I am currently working on a game project for school using HTML5 canvas and JavaScript. As I am still a beginner in JavaScript, I am facing a specific issue that I could use some assistance with. Despite trying various solutions, I have been unable to figur ...

Ensure that only one Bootstrap 4 collapse is expanded at any given time

I'm working on a project where I have multiple Bootstrap 4 collapse cards in my HTML. I want to ensure that only one card can be open at a time, and if another card is opened, all sibling cards should collapse. Please take a look at my codepen for ref ...

Modify the background color of column headers in a Material UI DataGrid as you scroll down vertically

In my React(NextJS) project using material UI, I have implemented tables (DataGrid component from material UI) with distinct background colors in the column headers, as shown below: https://i.sstatic.net/zd3Iu.png However, I encountered an issue where ra ...

Enhancing User Experience with Interactive React Hover Effects

Hello, I have tried various combinations but still cannot get the desired background color to display when hovering over my <p> element. I am looking for a CSS-only solution and not interested in using JavaScript hover events. I would appreciate it ...

Tips For Making Your Bootstrap 4 Page Fit Perfectly on Mobile Screens

Currently in the process of developing . The frontpage has been created and tested using Chrome's dev console's device toolbar. Ensured that the correct viewport is set and utilized Bootstrap's column system for stacking elements. However, ...

Is there a way for me to function without the need for resizing adjustments?

My Bootstrap web page is designed to remain fixed in size regardless of the browser window. I want it to be scrolled, not resized. Check out the image I uploaded: Correct Image Incorrect Image JSFiddle link <div class="row1 col-lg-12"> ...

Removing background color and opacity with JavaScript

Is there a way to eliminate the background-color and opacity attributes using JavaScript exclusively (without relying on jQuery)? I attempted the following: document.getElementById('darkOverlay').style.removeProperty("background-color"); docume ...

Unexpected issue with accessing the jQuery class descendant

I am currently developing a photo gallery and I am trying to add some CSS styling to the first photo that is visible within my #wrapper div. Below is the code snippet I have been working on: $('.inside:first-of-type>div:nth-of-type(1)').css(& ...

Adding products to an owl-carousel in an HTML document using JavaScript

When I try to add my products to an owl-carousel using JavaScript, the display is not correct. My HTML code looks like this: <div class="container mt-5 mb-5" data-aos-anchor-placement="top-center"> <div class="owl-carouse ...

Creating a scrollable container using CSS

I am currently working on a React project and encountered an issue with the CSS styling. I am looking for a solution that allows me to keep the parent and child components the same while enabling a scroll effect on the left side of the div containing shopp ...

Exploring ways to preview HTML using jQuery

As a newcomer to jQuery, I am looking for a way to preview the HTML content after clicking on an anchor tag. My setup involves a large textarea where users can input both HTML and CSS. Here is an example of my layout: <textarea type="text" rows=' ...

Step-by-step guide to creating a transition effect when the input changes

I'm looking to add a unique effect to my dropdown menu My goal is to create an effect in which the placeholder moves up and the new value seamlessly takes its place, using JS, jQuery, CSS, and HTML. View before transition View after transition ...

Guide on serving a static HTML file along with CSS styling

After meticulously crafting a static HTML Report embellished with stylish CSS, I intend to upload this report onto the server. Next, the HTML file will be transferred to S3 where a specialized service would promptly deliver the file directly to users' ...

Using Bootstrap to create a grid layout with an image

Where can I find a custom bootstrap grid similar to the one shown in the image below, with the red square being an image? https://i.sstatic.net/rgg0H.jpg I attempted to use this code but it didn't give me the exact outcome. How can I modify it to ac ...

SVG image element in Firefox does not respond to hover effect

I am currently working on developing an engaging SVG map. My goal is to have the image elements increase in size from 20px to 50px when hovered over. Below is an example of what I'm aiming to achieve: <svg xmlns="http://www.w3.org/2000/svg&quo ...

The presence of element a within the element ul is not permitted in this particular scenario. Additional errors from this section will not be displayed

Having trouble with this code snippet: <nav role="navigation"> <div id="menuToggle"> <input type="checkbox"/> <span></span> <span></span> <span></span> ...