Can we achieve this specific animation using CSS3 techniques?

I currently have an animated GIF file that I am trying to recreate using only CSS3 and one class. My attempt involved creating vertical stripes as a background image, animating them from left to right, rotating the image 45 degrees, adding the same image again positioned next to the first, and applying the same keyframe to rotate it 90 degrees. However, I ran into some issues and got stuck with my code.

You can see my attempt here: fiddle

I am looking to achieve this animation using just one class (although multiple pseudo elements are allowed). Hopefully, this is possible. Thank you for your help!

Answer №1

Check out my creative solution using just one element:

<div class="test">
</div>

No need for images, only cool gradients in the CSS:

.test{
    position: absolute;
    width: 400px;
    height: 400px;
    left: 20px;
    top: 20px;
    border: solid 2px blue;
}

.test:before {
    content: "";
    position: absolute;
    width: 50%;
    height: 100%;
    left: 0px;
    background-image: repeating-linear-gradient(135deg, white 10px, black 20px), 
                      repeating-linear-gradient(45deg, white 10px, blue 20px);
    background-size: 120% 50%;
    background-position: top left, bottom left;
    background-repeat: no-repeat;
     -webkit-animation: move 1s infinite linear; 
}

.test:after {
    content: "";
    position: absolute;
    width: 50%;
    height: 100%;
    right: 0px;
    background-image: repeating-linear-gradient(45deg, white 10px, green 20px), 
                      repeating-linear-gradient(135deg, white 10px, yellow 20px);
    background-size: 120% 50%;
    background-position: top left, bottom left;
    background-repeat: no-repeat;
    -webkit-animation: move 1s infinite linear reverse; 
}

@-webkit-keyframes move {
    0% {    background-position: -40px 0%, -40px 100%;}
    100% {  background-position: 0px 0%, 0% 100%;}
}

For a live demonstration, check out this webkit demo.

To make it compatible with older browsers, you may need to provide equivalents for CSS3 syntax.

I've color-coded the elements for clarity and included an updated version that works on smaller div sizes:

Updated demo

The background size has been adjusted to cover the element adequately:

.test:before,
.test:after {
    background-size: 120px 50%;
}

Enjoy experimenting with this fun CSS animation!

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

Radio buttons are not having the :invalid pseudo class properly applied

Looking to style a radio group with a required attribute. Attempting to adjust the appearance of the radio group depending on whether an input is selected or not. However, it appears that the :invalid pseudo-class does not apply to radio buttons. ...

The bootstrap pull-left and pull-right classes are not functioning properly when used in Angular

I'm currently working on this project in Angular and using Bootstrap. I'm trying to display the name and description on the left side and the image on the right, but it's not working as expected. Any help would be appreciated. You can find ...

Using CSS to overlay multiple text boxes onto an image at different positions

Can you help me solve this challenge? I have an image of a real property that will be randomly loaded into a DIV with a width of 200 pixels. The image needs to be resized to 200 pixels wide while maintaining its proportional height. Additionally, I have fo ...

The functionality of overflow:scroll is not functioning properly on Android smartphones

Hey there! I've been trying to implement scrolling in my application using overflow:scroll, but it seems that it's not working on Android mobile phones. After some research, I discovered that Android version 3.0 and below does not support overflo ...

Is there a way to update the value of an element that is continuously changing through a setInterval() function when hovering the mouse over it?

I am currently a novice working on developing a pomodoro timer. At the moment, when you click the button to start the timer, it switches to displaying the remaining time once activated. One of the features I want to implement is the ability for users to h ...

Hamburger icon is failing to appear in the collapsed navbar for certain items

My React application is not displaying the items of the collapsed navbar when using the Bootstrap navbar for mobile responsiveness. Can anyone please suggest what might be wrong here? <!-- Bootstrap 4.1.3 library --> <link rel="stylesheet" href ...

I require a breakdown of the JavaScript code, please

Are you struggling with a code snippet that involves CSS, JavaScript, and HTML? Let's take a look at the complete code: <!doctype html> <html> <head> <link rel="stylesheet" type="text/css" href="http://snipplicious.com/css/bo ...

Firefox is having issues when trying to print an iframe that is styled with display:none

Currently, I am implementing code obtained from an answer on Stack Overflow to enable direct printing of a separate page upon clicking a print button. The mechanism involves sending a URL to the print function which then loads the separate page into an ifr ...

Is there a way to adjust the size of a table display to ensure that both vertical and horizontal scroll bars are constantly visible?

[edits added below per the request to see code. Edits also added to the original post to clarify the ask - marked in bold] My application features a broad table with the potential for many rows, generated by django-tables2 using the bootstrap5-responsive ...

What is the process for enabling and disabling features in PHP?

<td>Notification for Unpicked Cases</td> <td> <input type="radio" name="notify" checked value="yes">Enable&nbsp;/&nbsp; <input type="radio" name="notify" value="no">Disable </td> If the user clicks the d ...

div is consistently correct across all web browsers

After creating the following CSS code for a div to always be positioned on the right: #button > .right { background-position: -268px 1415px; height: 180px; position: fixed; right: -90px; top: 40%; width: 263px; -webkit-transform ...

What is the best way to handle CSS and JavaScript for sub-templates when utilizing only a templating system?

When working with various templating systems in different languages, I often find myself facing the same question. First and foremost, The crux of the matter I am looking to implement a sub-template that includes a specific UI component which may be disp ...

Combine the jQuery selectors :has() and :contains() for effective element targeting!

I am trying to select a list item element that has a label element inside it. My goal is to use the :has() selector to target the list item and then match text within the label using the :contains() selector. Can I achieve this in a single line of jQuery ...

Do not apply tailwindcss styles to Material-UI

I've been struggling to apply styling from tailwindcss to my MUI button. My setup includes babel and webpack, with the npm run dev script as "webpack --mode development --watch". tailwind.css module.exports = { content: ["./src/**/*.{js, jsx, t ...

CSS login validator immobilized

In my Visual Studio project, I am facing an issue with applying CSS to two requiredfield validators. I have tried using the following code: #vdtrUserLogin { top:65px; left:750; position:absolute} #vdtrPasswordLogin0 { top:65px; left:900; position:absolute ...

Is it possible to target the initial sibling of a parent element using a CSS selector?

Is there a way to target the <p> element using only the id "Standort" as a constant? Any suggestions on how to accomplish this? <section> <header> <h2 class="licht"><span id="Standort" class="-sitemap-select-item-select ...

What's the best way to make sure the footer stays at the bottom of every page using CSS?

Here's the code I've been working on: #footer { font-size: 10px; position:absolute; bottom:0; background:#ffffff; } I'm facing an issue with this code - can anyone offer some assistance? UPDATE: To clarify the issue further: T ...

I'm having difficulty integrating boostrap with my react application due to issues with the css-loader

In my React index.js file, I am importing Bootstrap and using Webpack 4: import React from 'react'; import ReactDOM from 'react-dom'; import './assets/css/index.css'; import App from './App'; import * as serviceWork ...

Is it possible to simultaneously run watchify and node-sass watch together?

Currently, I am utilizing npm scripts in conjunction with watchify and node-sass while incorporating the -w parameter. I am curious if it is feasible to execute both of these 'watch' commands simultaneously. Would this setup ensure that only sty ...

Transforming traditional HTML table layout to modern div structure

We are currently in the process of transitioning old pages from our previous website structure, which used tables, to our new layout based on DIVs. Our website is structured using a PHP include system with separate components for the header, body, and foot ...