I am able to create progress bar with Bootstrap.
I want those numerical values to be displayed below the progress bar but not inside, something like this:
How can we achieve this? Do I need to use any JavaScript graphing libraries?
PS: Note that the main challenge I am facing is to show the numbers below divs, and not with color styling or calculating those numbers.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
<div class="container pt-4">
<div class="progress">
<div class="progress-bar" role="progressbar" style="width: 15%;">
15
</div>
<div class="progress-bar bg-success" role="progressbar" style="width: 30%;">
45
</div>
<div class="progress-bar bg-info" role="progressbar" style="width: 20%;">
65
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-Fy6S3B9q64WdZWQUiU+q4/2Lc9npb8tCaSX9FK7E8HnRr0Jz8D6OP9dO5Vg3Q9ct" crossorigin="anonymous"></script>
2
Answers
One solution would be to add a div below yours and to use some JavaScript
A little CSS whizbang and some pseudo-elements should do. Note that I wrapped the numeric values with spans for positioning. By giving the structure a custom class we can override Bootstrap’s styles without using
!important
, which makes work easier down the road and avoids styling all progress bars.Also note that Bootstrap provides classes for position, overflow, and border-radius, but I’ve put those things in the CSS for clarity. I did use border classes on the outer element.