Guide to adjusting animation timing with CSS

Looking for a way to set a custom animation timing? I'm attempting to create a police flash animation with specific timings but facing some challenges. The animation involves two colors - red and blue. My goal is to have blue flash for 1 second, then stop flashing, followed by red starting to flash. Once red stops flashing, blue will begin flashing again.

Answer №1

Maybe this solution will be of assistance to you.

.blue {
  animation: bluePoint 2s infinite;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: blue;
}
.red {
  animation: redPoint 2s infinite;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: red;
}
@keyframes bluePoint {
  0% {opacity: 1}
  12.5% {opacity: .5}
  25% {opacity: 1}
  37.5% {opacity: .5}
  50% {opacity: 1}
  100% {opacity: 1}
}
@keyframes redPoint {
  0% {opacity: 1}
  50% {opacity: 1}
  62.5% {opacity: .5}
  75% {opacity: 1}
  87.5% {opacity: .5}
  100% {opacity: 1}
}
<div class="blue"></div>
<div class="red"></div>

Answer №2

Create a captivating 2-second animation that alternates between a flashing blue light and a flashing red light. The blue light will flash for the first second (0-50% of animation time), while the red light will flash from 50-100% of the animation time.

Implement this effect using keyframes, following the example provided below.

To ensure the animation loops continuously, utilize the infinite attribute;

body {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  width: 100vw;
  margin: 0;
  background-color: black;
}

div {
  height: 50px;
  width: 100px;
}

.blue {
  animation: 2s infinite flashblue;
}

.red {
  animation: 2s infinite flashred;
}

@keyframes flashblue {
  0% {
    background-color: lightblue;
  }
  25% {
    background-color: darkblue;
  }
  50% {
    background-color: lightblue;
  }
  100% {
    background-color: lightblue;
  }
}

@keyframes flashred {
  0% {
    background-color: salmon;
  }
  50% {
    background-color: salmon;
  }
  75% {
    background-color: firebrick;
  }
  100% {
    background-color: salmon;
  }
}
<div class="blue"></div>
<div class="red"></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

What is the best way to iterate through and hide these images when they are clicked on?

I need help creating a grid of images inside divs that function like checkboxes. When you click on an image, it should disappear, and clicking again should make it reappear. I have some code that works for one image, but I can't figure out how to loop ...

Change the value of a cell in a table dynamically with the use of Angular

I am currently developing a web application using Angular 6. Within the HTML template, I have included some code that showcases a specific part of an array within a table cell. It's worth noting that the table is constructed using div elements. <d ...

Tips for creating a disabled appearance for a font awesome icon button:

I'm currently using a font awesome icon button and I'm looking to create a disabled state for the icon. Although I can achieve a disabled button appearance using the Bootstrap disabled class, the button remains clickable. Is there a way to make i ...

Tips for adjusting the header color in materialize framework?

I've been working on a web template and I'm looking to customize the color displayed in the Android browser (maybe using JS?). The default color is blue. How can I go about changing it? https://i.sstatic.net/RxLbS.jpg Appreciate any help! ...

Troubleshooting a CSS problem within Visual Studio Code

Just started using VS Code and I'm having trouble getting my CSS to work. The link seems to be fine since it opens with click + ctrl, and both files are in the same folder. So why isn't it applying the styles? https://i.sstatic.net/yRysK.png Ed ...

What's the reason for text-alignment not functioning properly?

After some testing, I have come up with the following code: .Greetings { width:100%; display:block; text-align:center; font-family: "Times New Roman", Times, serif; font-size:75px; color:#208CB7; } The objective was to center the text on the ...

While examining the HTML elements, it appears that they are not in their correct positions

Here's a visual representation of the issue. Imagine my mouse cursor as the red painted mouse because print screen doesn't capture the actual cursor. Oddly enough, the element is being highlighted even though the cursor is not directly positione ...

Web link button

Here's a question about buttons: <p> Upload:<br> <br> <input type="file" name="datafile" size="40"> </p> Can a button be created where users can paste a URL of an image from the web? For example, I would lik ...

What is the best way to create a dropdown menu within an iframe that appears on top of all other frames?

The code snippet below is from my frameset.jsp file: </head> <iframe width="100%" src="mail_frame.html"></iframe> <iframe width="105px" height="100%" src="sidenav.html" id="leftnav" name="leftnav" ></iframe> ...

Adjustable design and content containment

Currently, I am exploring ways to utilize CSS in order to control the layout of my website effectively. My goal is to have the main frame of the website contain and confine all content within it. However, since I have not written any code yet, allow me to ...

The jQuery dynamic fields vanish mysteriously after being validated

I am facing an issue with my jQuery and validation. Below is the code snippet causing the problem: var fielddd = 1; $(document).on('click', '.btn.add-field', function() { fielddd++; $('#newfield').append('< ...

The tag <li> is not allowing enough room for the content to expand as needed

I am trying to create a list using ul li elements. When the content inside the li exceeds the width, a scrollbar appears. However, I am encountering an issue where the li tag does not cover the entire width and spills outside. .container{ b ...

Tips for ensuring two blocks, each containing two pairs, remain next to each other within a div without being separated

As a newcomer to HTML/CSS and Liquid, I am exploring the creation and styling of custom blocks on a Product Page. My goal is to display these custom blocks in pairs within a single div. The current code structure I have implemented functions well, with on ...

Tips for overlaying a button on top of an image using CSS

I am currently working on a project where I need to position a button over an image. My reference for this task is the W3schools CSS website, and I have made some modifications to the code provided in the link here: https://www.w3schools.com/css/tryit.asp ...

Guide on grabbing characters/words typed next to # or @ within a div element

Within a div element, I have enabled the contenteditable property. My goal is to capture any text input by the user after typing '#' or '@' until the spacebar key is pressed. This functionality will allow me to fetch suggestions from a ...

Div with Sticky Header and Scrolling Ability

I am working on a project that involves creating a scrollable div with "title" elements inside. I want the title element of each section to stick to the top of the div as I scroll, similar to how a menu sticks to the top of a webpage. An example of this ca ...

Scaling down the screen for a smaller display

Having trouble achieving a specific effect and could use some assistance. My goal is to create an action where, upon clicking on the nav element (for simplicity, I've set it to be triggered by clicking anywhere on the body), the following should occur ...

Tips for breaking free from an html string with numerous double quotation marks

After receiving a string from an ajax request, the content looks like this: According to json doc, "quotes should be escaped" This information is stored in data.description, and inserted into the template like so: '<a href="#"' + ' ...

How to Manage Posts in Laravel with Controllers: Deleting and Updating

{!! Form::open(['action'=>['PostsController@update',$post->id],'method'=>'POST']) !!} <div class="form-group"> {{Form::label('title', 'Title')}} {{Fo ...

Developing an interactive website utilizing AngularJS, WCF Service, and SQL Server

Exploring the possibilities of creating a web application, I stumbled upon AngularJS. With plans to incorporate WCF Service and SQL Server into my project, I am intrigued by what these technologies can offer. I want to ensure that AngularJS aligns with my ...