What is the best way to create a two-step animated progress bar using CSS animations?

Is it possible to create a two-step progress bar animation where the red bar transitions to yellow in the middle, followed by another yellow bar moving to the end?

I attempted using "display: none" in the progressbar2 class, but it disappears at the start. How can I make the yellow bar (class: progressbar2) appear after 2 seconds without showing initially?

Here is the code on CodePen

.container1 {
  position: relative;
  width: 100%;
  margin-top: 10px;
}

.progress1 {
  height: 10px;
  width: 50%;
  background-color: yellow;
  border-radius: 2px;
  animation: becomeyellow 2s linear;
  display: flex;
  float: left;
}

.progress2 {
  height: 10px;
  width: 50%;
  position: absolute;
  left: 50%;
  background-color: green;
  border-radius: 2px;
  animation: becomegreen 2s 2s linear;
}

@keyframes becomeyellow {
  0% {
    width: 0%;
    background-color: red;
  }
  100% {
    width: 50%;
    background-color: yellow;
  }
}

@keyframes becomegreen {
  0% {
    width: 0%;
    background-color: yellow;
    display: none;
  }
  100% {
    width: 50%;
    background-color: green;
  }
}
<div class="container1">
  <div class="progress1"></div>
  <div class="progress2"></div>
</div>

Answer №1

At the end of my code for the progress2 class, I included the property opacity:0.

Additionally, in the becomegreen animation, I added opacity:1 when reaching 100% completion.

This adjustment produced successful results.

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

Issue with Image Transition while Linking

I have been attempting to create transitions between images using links. I followed the steps in 'Demo 6' from this page (http://css3.bradshawenterprises.com/cfimg/), but unfortunately, it did not work as expected on my testing website (danitheme ...

Search button in Bootstrap navbar misplaced

Following Dennis Ivy's tutorial on an ecommerce site, I attempted to implement the navbar from here (the first example). However, after copying and pasting the code and ensuring proper indentation, the search field and button appear misplaced. A snipp ...

The jQuery placeholder plugin encounters an error stating 'jQuery is not defined'

Having an issue on this specific page where I keep encountering a 'jQuery is not defined' error in both Chrome and IE because of the jQuery placeholder script. The declaration of jQuery comes before the plugin script. Checked for any conflicts ...

Is it necessary for children to occupy the same area while beginning from the coordinates 0, 0?

Imagine a scenario where you have a modal with tabs and tab content. Each tab has a different height - the first tab is 100px high, the second tab is 500px high, and the third tab is 50px high. The challenge here is to ensure that the modal body always mat ...

Set the dimensions of the style div to match those of the image it contains

I am struggling to position a div or button so that it matches the dimensions of the image it contains, without exceeding the dimensions of the parent div(s). Despite my efforts, I can't seem to get it right for both vertical and horizontal images. W ...

Find the identifier that does not currently exist in the collection of objects

There is a situation where I have an array and an object that consists of arrays of ids, which are essentially permission objects. My goal now is to extract the ids that do not exist in the given object. Can someone assist me with devising the necessary l ...

Implementing checkbox selection to dynamically alter button color

I have 5 rows of green buttons, each row containing 30 buttons. When a button is clicked, a modal pops up with a checkbox inside. If the checkbox is checked, I want the button to change to red. I've tried a few methods, but none have been successful. ...

Multiple CSS styles are being employed simultaneously to render the webpage

Currently, I am utilizing JavaScript to choose different CSS styles for various accessibility options such as black on white text and larger text. The issue I am facing arises when switching the CSS sheet, as elements from previously selected sheets are st ...

Enhancing navbar with a dropdown menu in CSS

Is there a way to add a dropdown menu to my navigation bar and make it visible when hovered over? Any help or support would be greatly appreciated. Here is the code I have on JSFiddle: http://jsfiddle.net/nbh2e15y/2/ The CSS: #nav { background: none ...

Issues with positioning divs in the header and main sections

I'm struggling with positioning the divs inside the header div on my page that has 3 parent divs. Here is a snippet of my code: Divs layout: <div id="layout"> <div id="header" class="body"> header <div id="logo"> ...

Issue with Nav Bar Toggle not changing text to white color

Query I'm baffled as to why the text in the navigation bar (when opened with the Burger Menu) refuses to turn white. I've exhausted all efforts to change the color to white. Please assist me in pinpointing why the text remains unaffected when t ...

How can you alter the background color of a Material UI select component when it is selected?

I am attempting to modify the background color of a select element from material ui when it is selected. To help illustrate, I have provided an image that displays how it looks when not selected and selected: Select Currently, there is a large gray backgr ...

Turn off the ability to click on images, but allow users to access the right

https://i.stack.imgur.com/jriaP.png Example image sourced from reddit.com Illustration represents the desired effect using CSS and possibly JS. In essence: I aim to make an image on a website unclickable to its imageURL There should be a context menu ...

The concept of AJAX send function and toggling button visibility

I am facing a challenge with a textarea and send button on a panel that is displayed after entering the first character. The visibility of the button is controlled by the isButtonVisible() method. Once clicked, it sends the text from the textarea using the ...

Exploring the world of nested selectors in conjunction with Vue.js CSS modules

Can nested css selectors be used with Vue.js css modules? For example, I am trying to scope this css (to avoid affecting child components): .list { ... .item { ... } } The documentation only provides examples without nesting, but is ...

How do I ensure that a fieldset and a multiple selection box have equal heights using CSS?

Is there a way to make the multiple selection box the same height as the fieldset, without using JavaScript? I have a form with a fieldset and select box side by side, and any assistance would be appreciated. <!DOCTYPE html> <html lang="en> ...

Having difficulty retrieving text from textarea with jquery

I'm experiencing an issue with my jquery script where the top two buttons are showing 'undefined' instead of performing the same action as the buttons below them. Could someone please pinpoint where I went wrong? I want the two buttons at t ...

using `clear: both` does not stop text from wrapping

Currently, I am facing an issue with positioning 3 divs in my layout. Two of the divs are floating to the left and right respectively, while the third one should be placed under the two others. I tried using clear: both but it doesn't seem to work as ...

Having trouble with the JavaScript DOM rewrite for aligning text?

function modifyTextAlignment(){ document.getElementById("th1").style.textAlign = "right"; } #th1{ text-align:left; } <table> <tr><center><th colspan="2" id="th1">List of Important Emergency Contacts</th><center></tr& ...

Navigate to a web page coded in HTML using Vue JS

I am currently utilizing Vue.js. My goal is to redirect from my Vue component to a standard HTML page. Since it involves a License Agreement that cannot be converted into a Vue component, I am looking for a way in Vue to link to an HTML page and open it ...