My CSS progress bar renders everything except the inline style is not applied so the size of the progress contents does not dynamically change as expected. The value of {{ field_ct_rack_left_pdu__value }} is pushed from a Drupal View.
Here is the HTML:
<div class="iab-progress-bar" data-label="{{ field_ct_rack_left_pdu__value }}%" style="width:{{ field_ct_rack_left_pdu__value }}%"</div>
Here is the CSS:
.iab-progress-bar {
position: relative;
box-sizing: border-box;
width: 100%;
height: 3em;
background-color: #111;
border-radius:1em;
color: white;
margin-bottom:10px;
}
.iab-progress-bar::before {
content: attr(data-label);
display: flex;
align-items: center;
position: absolute;
left: .5em;
top: .5em;
bottom: .5em;
/*width:3%;*/
min-width: 2rem;
max-width: calc(100% - 1em);
background-color: #fc7703;
border-radius: 1em;
padding: 1em;
}
When I use the width: attribute in the .iab-progress-bar::before selector the bar expands as expected.
The data-label attribute contains the correct value.
I have tried playing around with the data-label attribute in the width: selector but of course I have not been successful.
Thanks for your time and thoughts.
2
Answers
Try like this
Now it works dynamically while changing the value
You have to change width of
.iab-progress-bar::before{ }
You can animate this using animation (
@keyframes
) ,or rewrite html, css and use javascript – see example: w3schools