I have a Bootstrap progress bar. I’d like the last div, which has the classes bar
bar-warning
to occupy everything that isn’t already occupied by the other inner divs without me having to do calculations. i’d like to get something like width: everything-else
, however obviously that isn’t valid css. i’ve tried different solutions, such as making the width auto
, 100%
, -100%
etc, but none of these work sadly.
An alternative solution would be to just put the text into that area and center it relative to the non-filled area. However, I couldn’t do that either.
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.2/css/bootstrap.css" integrity="sha512-Fik9pU5hBUfoYn2t6ApwzFypxHnCXco3i5u+xgHcBw7WFm0LI8umZ4dcZ7XYj9b9AXCQbll9Xre4dpzKh4nvAQ==" crossorigin="anonymous" referrerpolicy="no-referrer"
/>
<div class="progress progress-striped">
<div class="bar bar-success" style="width: 14.5%;"></div>
<div class="bar bar-info" style="width: 14.6%;"></div>
<div class="bar bar-warning" style="width: 70.9%;"></div>
</div>
2
Answers
For a no-CSS solution, just put the warning bar styles on the chart itself, so they show wherever other bars don’t.
We can hack the markup a bit to take advantage of Bootstrap’s style classes. By moving the controlling class out a level we maintain the ancestral relationship necessary to do so. This eliminates the need for a final bar, but if you do have one it doesn’t have a width anyway, so it’s not a problem.
If you actually need the final bar to be present and the proper size, you can use flexbox.
You can use flex for this: