Vibrant progress bar design with CSS

Could someone assist me in coding a multicolor progress bar? I would like it to display red when the progress is less than 50, green when the progress is between 50 and 90, and blue when the progress is between 90 and 100. How can I achieve this?

Answer №1

To display a progress bar, you can create a main div for the progress bar container and nest smaller divs inside it to represent different progress levels.

<div class="progress-bar">
    <div class="fifty-percent">
        <p>50%</p>
    </div>
    <div class="twenty-five-percent">
        <p>25%</p>
    </div>
    <div class="ten-percent">
        <p>10%</p>
    </div>
</div>

`

For the styling, you can use CSS similar to the following: `

    .progress-bar {
        width: 100%;
        height: 30px;
        border-radius: 10px;
        background-color: #b3b3b3;
        color: white;
        text-align: center;
    }

    .fifty-percent {
        width: 50%;
        height: 100%;
        background-color: green;
        float: left;
        border-top-left-radius: 10px;
        border-bottom-left-radius: 10px;
    }

    .twenty-five-percent {
        width: 25%;
        height: 100%;
        background-color: orange;
        float: left;
    }

    .ten-percent {
        width: 10%;
        height: 100%;
        background-color: red;
        float: left;
    }

`

Answer №2

Introducing a vibrant multicolor progress bar that you can customize. View it in action on my Codepen page: https://codepen.io/onlintool24/pen/dyVJrww

All it takes is adjusting the 'progressval' variable to witness the dynamic changes in the progress bar colors and completion status.

var progressval = 50;
var elm = document.getElementsByClassName('progressab')[0];
elm.style.width = progressval+"%";

elm.innerText = "You're "+progressval+"% There!";

if(progressval>90 && progressval<=100 ){   elm.style.backgroundColor = 'blue';                                 
}else if(progressval>50 && progressval<90 ){ elm.style.backgroundColor = 'green';
}else if(progressval<=50){ elm.style.backgroundColor = 'red';
}
.progressa {
    border-radius: 50px !important;
    height: 35px;
    line-height: 36px;
    font-size: 14px;
    overflow: hidden;
    height: 35px;
    margin-bottom: 20px;
    background-color: rgba(0,0,0,0.5);
    border-radius: 4px;
    -webkit-box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
    line-height: 36px;
    height: 35px;
    font-size: 14px;
    border: 3px solid transparent;
}
.progressab {
    background-image: -webkit-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);
    background-image: -o-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);
    -webkit-background-size: 40px 40px;
    background-size: 40px 40px;
    -webkit-transition: width .25s ease,height .25s ease,font-size .25s ease;
    -moz-transition: width .25s ease,height .25s ease,font-size .25s ease;
    -ms-transition: width .25s ease,height .25s ease,font-size .25s ease;
    -o-transition: width .25s ease,height .25s ease,font-size .25s ease;
    transition: width .25s ease,height .25s ease,font-size .25s ease;
    width: 0;
    color: #fff;
    text-align: center;
    font-family: 'Open Sans',sans-serif !important;
    animation: progress-bar-stripes 2s linear infinite reverse;
}

@keyframes progress-bar-stripes{
0% {
    background-position: 40px 0;
}
100% {
    background-position: 0 0;
}
}
<div class="progressa">
<div class="progressab" style="    background-color: rgb(178, 222, 75);"></div>
</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

It is not possible to dynamically change the value of a checkbox using jQuery when it is checked or

When the checkbox value is changed to 1, it cannot be changed back to 0 when unchecked. $('.ChkBox').change(function() { if ($(this).attr('checked')) { $(this).val('1'); } else { $(this).val('0'); } ...

Warning: The class name hydration discrepancy between server and client (Caution: Property `className` does not correspond between the Server and the Client)

Trying to figure out if my problem is a stubborn bug, a support issue, or just a configuration mismatch has been quite the journey. I've spent so much time on this, not exactly thrilled to be reaching out for help. After searching for 3 days and only ...

Retrieve the chosen date from a DatePicker using a Javascript function

Is there a way to retrieve the user-selected date using a JS function? I attempted this method: var test = $("#datepicker").datepicker( 'getDate' ); However, when I display it with an alert, it shows [object object] instead of the date. This ...

My goal is to develop a custom forEach function that retrieves a substring from each element in an array

I have a file containing image names like: sciFi.png, posed.png, birdA.png, dolphin.png, horse.png, shake.png, loft.png, basement.png, avenger.png, friend.png In my JavaScript document, I am trying to read this file and convert it into an array. Then, I w ...

Encountering an issue with WebDriver in the realm of JavaScript

I am struggling to use JavaScript to locate specific controls and send values to them. One example is changing the text in a textbox with the ID "ID" to "123456". Below is the code I tried: ((IJavaScriptExecutor)driver).ExecuteScript("document.getElement ...

Issue arose following implementation of the function that waits for the event to conclude

I've encountered a problem with my HTML and jQuery Ajax code. Here's what I have: <form> <input name="name_field" type="text"> <button type="submit">Save</button> </form> $(document).on("submit", "form", fu ...

Utilizing CSS3 to apply a customized background color to every set of three table rows

Is it possible to achieve what I want using CSS3 without Javascript? I've experimented with nth-child and nth-of-type, but couldn't get it to work. I have three table rows that I want to give a background color to, but the table rows beneath them ...

Guide to Including an Object in AngularJS Scope

I am completely new to Angular JS and mongod. My goal is to add a new ingredient field to this page for the specific drink that the + button is clicked on. Here is how my view looks like: UI Image This is what my .jade file contains: block content ...

What is the best way to transfer an object between views in Django?

Background/Issue In my web application, I have a job that involves running a python script to log into LinkedIn. This script launches headless chromium, navigates to the LinkedIn login page, and logs in with the proper credentials. However, sometimes Link ...

Creating a number of arrays based on the row of a .CSV file can be accomplished in Angular by utilizing the

Implementing an Angular template to read .CSV files and generate a table involves creating two separate files: one for the header and another for the table content. For the header CSV file: header.csv https://i.stack.imgur.com/ojMo6.png For the table da ...

What is the best way to rearrange the elements in a database after they have been displayed?

I have a feature on my website where you can enter text into a textbox and then click a button to save it in a database. The saved entries are displayed along with buttons for deleting an entry and moving it to the top of the list. <?php $resultset2 = ...

Utilizing AJAX to load a WAV file

One of the tasks I'm working on involves a collection of audio files. When a file from this list is clicked, I want JavaScript to load and display the waveform of that specific audio file. The following function is responsible for drawing the wavefor ...

Experiencing ERR_TOO_MANY_REDIRECTS while using Next.js with Vercel and a Custom Domain through Cloudflare

I'm having trouble getting my Next.js project set up on Vercel with a custom domain managed through Cloudflare. Despite configuring the DNS and SSL settings correctly, I keep seeing a net::ERR_TOO_MANY_REDIRECTS error when trying to access my site at ...

The Twilio JWT authentication token has expired

I'm currently utilizing Twilio voice call functionality and everything is working smoothly. However, the Twilio JWT token expires every hour, forcing users to refresh the page periodically. I'm seeking advice on how to extend the token validity p ...

Is there a way to dynamically add an option to multiple select boxes and then only redirect the browser if that specific option is chosen using jquery/js?

Presently, this is the code I am working with. The URL validator is specifically included because there was an issue with redirection occurring on any option selected, however, I only want a redirect to happen when the options I add with jQuery are clicked ...

Anguar server encountered a startup issue and failed to initialize

My server.js file looks like this: var express = require('express'), api = require('./api'), app = express(); app .use(express.static('./public')) .use('./api', api) .get('*', ...

Building Your Own Array Object in JavaScript

Yes, it may seem crazy at first glance, but let me clarify things a bit. When using Jquery, for instance $('div'), it returns an Array Collection similar to this: [div#container, div#header, div#logo]. The interesting part is that primitive Arra ...

Display unique JQuery special characters

I'm looking to modify this specific text Hello Mr ABC so that it appears as: Hello "Mr ABC". The text Mr ABC includes a unique non-printable character " ". P.S: Where can I find more information on this topic? ...

When clicking on an image, it triggers a unique PHP query, however the results obtained are not accurate

Greetings, I have a search feature on my website. When a user inputs a keyword and clicks the search button, it directs them to jobsearch.php which then displays a list of relevant jobs from the MySQL database. The functionality is working perfectly. Howe ...

"TailwindCSS opts for the inclusion of prefexied utilities instead of relying

Trying to set the height of the div to h-2, with a class that includes height animation on medium devices. The issue is that even though h-2 should be used on mobile, tailwindcss still uses h-20 instead. Any thoughts on why this may be happening? Here i ...