CSS3 Animation displaying text color change on various elements in a continuous loop

I was attempting to create a dynamic animation where multiple texts change color, similar to what you can see on https://vercel.com. I have successfully figured out how to make one text change color using keyframes, but I am struggling to make each text change color in a specific pattern.

For example, take a look at this image: enter image description here. The word Develop begins in red, then switches to black before transitioning to the word Preview in blue. After that, it changes back to black and the word Ship turns yellow. This sequence should repeat endlessly.

Below is the current code that I have been working with:

.center {
    margin: 0 auto;
    padding-top: 10rem;
}

.awesome {
    width: 100%;
    margin: 0 auto;
    text-align: center;
    color: #313131;
    font-size: 45px;
    font-weight: bold;
    position: flex;
    -webkit-animation: color-change-red 10s infinite alternate;
    -moz-animation: color-change-red 10s infinite alternate;
    -o-animation: color-change-red 10s infinite alternate;
    -ms-animation: color-change-red 10s infinite alternate;
    animation: color-change-red 10s infinite alternate;
}

@-webkit-keyframes color-change-red {
    0% { color: red; }
    33.3% { color: black; }
    100% { color: black; }
}
@-moz-keyframes color-change-red {
    0% { color: red; }
    33.3% { color: black; }
    100% { color: black; }
}
@-ms-keyframes color-change-red {
    0% { color: red; }
    33.3% { color: black; }
    100% { color: black; }
}
@-o-keyframes color-change-red {
    0% { color: red; }
    33.3% { color: black; }
    100% { color: black; }
}
@keyframes color-change-red {
    0% { color: red; }
    33.3% { color: black; }
    100% { color: black; }
}

Answer №1

Upon analysis, it is evident that the linked example site showcases colored words staying vibrant for a brief moment before transitioning to black.

This code snippet retains the color of each word for 30% of the animation duration, swiftly transitioning them to black as one-third of the animation elapses.

An additional observation reveals a substantial amount of repetitive code in this snippet, potentially causing confusion regarding its functionality.

The implementation ensures uniform animation for all words, with the second word delayed by one-third of the total time and the third word delayed by two-thirds.

In addition, a CSS variable determines the color, allowing reuse of the keyframes code for each word.

To enhance clarity, the snippet removes browser-specific settings; users can reinsert these as needed based on their specific requirements.

.center {
  margin: 0 auto;
  padding-top: 10rem;
}

.awesome {
  width: 100%;
  margin: 0 auto;
  text-align: center;
  color: #313131;
  font-size: 45px;
  font-weight: bold;
  position: flex;
  --duration: 10s;
  animation: color-change var(--duration) infinite;
}

.awesome:nth-child(1) {
  --color: red;
}

.awesome:nth-child(2) {
  --color: blue;
  animation-delay: calc(var(--duration) / 3)
}

.awesome:nth-child(3) {
  --color: yellow;
  animation-delay: calc(var(--duration) * 2 / 3);
}

@keyframes color-change {
  0% {
    color: var(--color);
  }
  30% {
    color: var(--color);
  }
  33.3333% {
    color: black;
  }
  100% {
    color: black;
  }
}
<div class='center'>
  <p class="awesome">Develop</p>
  <p class="awesome">Preview</p>
  <p class="awesome">Ship</p>
</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

How to Fix Items Being Pushed Down by 'Particleground' Jquery Plugin Due to Z-Index and Positioning

I'm grappling with understanding z-index and positioning, despite reading various questions and articles on the topic. Currently, I'm attempting to incorporate a Jquery Plugin called 'Particleground': https://github.com/jnicol/particle ...

"Discover the power of Algolia's docSearch feature

Currently, I am working on integrating Algolia DocSearch into my docusaurus project. After obtaining the api key and api id from Algolia, I am unsure of the next steps to take. I would appreciate guidance on the necessary procedures that need to be followe ...

How can we use Python and Selenium to retrieve the text from HTML that includes the <p> tag?

I have a simple question that I hope you can help me with. I'm not feeling well and struggling to complete my presentation because my brain just isn't functioning properly. Here is the HTML code in question: <p> <b>Postal code:& ...

Solving Typing Problems in React TypeScript with "mui-icons" Props

I have a small compost project with only an App.JSX file that is functioning perfectly, but now I need to convert it to App.TSX. After changing the extension to .TSX, I encountered two errors that I'm unsure how to resolve. function MyComponentWithI ...

Utilize conditional styling along with hover effects in ReactJS

I'm facing an issue where I need to set up a conditional style and a hover effect for TableRows. They work fine individually, but when combined, the hover function stops working. CSS const StyledTableRow = withStyles((theme) => ({ root: { tab ...

Avoid clicking on links while the webpage is still loading

I am facing an issue with my website where I need to intercept link-clicking events using jQuery. Everything works fine, but there is a problem if a user clicks on a link before JavaScript finishes loading, causing it to redirect to another page in error. ...

Employing CSS animations to elevate div elements

Currently, I am working on animating a table of divs and trying to achieve an effect where a new div enters and "bumps up" the existing ones. In my current setup, Message i3 is overlapping Message 2 instead of bumping it up. How can I make Messages 1 and 2 ...

Sometimes, Vercel/Next.js has a habit of unexpectedly throwing 404 errors when `{"notFound": True}` is returned

Introduction We apologize for the inconvenience of not being able to provide a reproducible example at this time. Our team has been diligently investigating a bug that seems to be quite elusive. For the past week, we have been grappling with an issue in o ...

Guide to accessing JSON APIs by utilizing a link within another API that contains JSON data linking to yet another JSON file

Searching for a Solution to Fetch Data from a Specific URL and Display it on a New Screen I have successfully called the API using the following link: - Completed After receiving JSON data, I was able to populate my DataTable. - Completed Upon clicking a ...

I'm experiencing difficulty in scrolling on my Nextjs web application

Currently, I am facing an issue with my portfolio webpage which is divided into 3 main components - Hero, About, and Portfolio. The layout structure is as follows: export default function RootLayout({ children, }: { children: React.ReactNode }) { ret ...

Instructions for securing a React Front End with Node.js Express-Sessions authentication:

I have decided to move away from using Firestore auth in order to develop my own authentication system. Here is my goal: To create a React web app that allows users to sign up and sign in. Authenticated users should be able to interact with a REST API, w ...

PHP MySQL outputting data in a dropdown menu format

Struggling to extract data from a database and display it as a dropdown list. I am fetching the foreign key, its unique code, and its name/title to be displayed in a dropdown list for input into a new table. $sql = "SELECT quali_code, title FROM ...

The onClick function within the .map function is continuously triggered

I am encountering an issue with my code where a Dialog confirmation prompt from Material UI keeps getting called unexpectedly. The problem seems to arise when I add a value to the function that is triggered by a button click within a loop of an array usi ...

Discrepancies in Video Element Size: Mobile Versus Desktop

Why does the video element have different sizing behavior between mobile and desktop? I noticed on this website that on desktop Chrome, its width is about 35% of the browser while on iPad Chrome it's only about 10% Does anyone know why this is happen ...

When I click on a tab section to expand it, the carat arrows all point upwards. Only the arrows corresponding to the selected section should

click here for imageIt appears that there are four tabs, each with a click function on the carat icon. When I expand one tab, all carats point upwards instead of only the selected one appearing. accountSelection(account) { if (!this.selectedAccoun ...

The necessary type "ID!" for variable "$projectId" was not given 400 Bad request

Using Apollo Client Query to Fetch Project Data `export const GET_PROJECT = gql` query singleProject($projectId: ID!) { getProject(projectId: $projectId) { _id name description status } } ;`` Implementing useQuery Hook ...

Utilizing the Double Mapping Feature in React with Typescript

It seems I might be overlooking something, can someone guide me on how to properly double map in this scenario? I'm encountering an error on the second map: Property 'map' does not exist on type '{ departure: { code: string; name: strin ...

Ways to reduce the size of images within a bootstrap carousel

I'm currently working on creating a carousel that will serve as a background image cover for my website, similar to the revolutionary slider in WordPress but without using a plugin. I am developing it specifically for my static website. The challenge ...

Tips for integrating Stripe into a React test

I am currently conducting a test on a React component that utilizes Stripe, and I am unsure about the best way to structure the test. An error message has been popping up as follows: Error: In order to use react-stripe-elements, ensure that Stripe.js ( ...

The css values for component _nghost-c0 in an Angular application

Recently, I've been delving into Angular 5 and couldn't help but notice the peculiar html tags with ng generated attributes like _nghost-c0 and _nghost-c1... This got me wondering, what exactly do these attributes signify? [_nghost-c3] .employee ...