I am putting together a bootstrap progress bar with a number of step, each step is assigned against a variable (in %).
I am trying to position these variables on the bar.
The below picture is the current result I get to
This is not satisfactory as the awesomefont icons are contained within the bar and would like to have them on top like in this example. The problem on this picture is obviously that the bar length is not the same as the length used to position the icons.
Finally, it seems the left side of the icon starts at the % required to achieved the step. I would ideally prefer to have them centered on the targeted % – if the target is 5%, instead of having the icon start at 5% on the bar, I would like to have it so that the center of the icon is at 5%.
Any takers?
css
.bar-step {
position:absolute;
margin-top:-4px;
z-index:1;
font-size:12px;
}
.label-line {
background: #000;
height:50px;
width:1px;
margin-left: 5px;
}
.label-percent {
margin-left: 5px;
}
.dot {
height: 25px;
width: 25px;
background-color: #bbb;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
position: relative;
outline: 2px solid white;
}
.dot i {
position: initial;
}
.progress {
position: relative;
}
html
<div class="progress">
{% for venue_id, reward_position_on_bar in reward_positions.items %}
{%if venue_id == key%}
{%for reward_position_on_bar in reward_position_on_bar%}
<div class="bar-step" style="left: {{reward_position_on_bar.2}}%">
<div class="dot">
<i class="fa-solid fa-gift fa-lg" style="color: #ffffff;"></i>
</div>
</div>
{%endfor%}
{%endif%}
{% endfor %}
<div class="progress-bar bg-success" role="progressbar" style="width: {{value}}%; left: 0;" aria-valuenow="{{value}}" aria-valuemin="0" aria-valuemax="100"></div>
</div>
2
Answers
Here’s one approach:
Notes:
You can ignore the CSS section that’s for visual debugging purposes.
Basically, we use some CSS variables to set the icon size along with the padding that we add for styling purposes and then use that to calculate an offset in order to center the icons right at the percentage point in the bar.
Changed your css a bit. Marked the imported lines with comments.