Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the color of a bootstrap (twitter) progress bar at runtime

I am using this progress bar :

http://twitter.github.com/bootstrap/components.html#progress

And would like to give it a custom color, known only at runtime (so hardcoding it in the css or less file is not an option)

I have tried this :

<div class="progress">
  <div id='pb' class="bar" style="width: 80%"></div>
</div>

<script>
  $('#pb').css({'background-color': "red"})
</script>

without success.

like image 313
Max L. Avatar asked Mar 31 '12 02:03

Max L.


People also ask

Which bootstrap 4 class is used to add stripes to a progress bar?

Striped. You can also make the Bootstrap progress bar striped by using progress-bar-striped class.


2 Answers

Your code is actually working, just that the progress bar is actually using a gradient as a color instead of a solid background-color property. In order to change the background color, set the background-image to none and your color will be picked up:

$('#pb').css({
    'background-image': 'none',
    'background-color': 'red'
});
like image 133
Andres Ilich Avatar answered Sep 20 '22 08:09

Andres Ilich


There is now a bootstrap 3.2 progress bar designer tool.

http://bootstrapdesigntools.com/tools/bootstrap-progress-bar-designer/

like image 24
Brandon Clark Avatar answered Sep 21 '22 08:09

Brandon Clark