Currently, I am trying to create a health bar-like element but I am facing difficulties in centering the text within it. Despite exhausting all my options, the text is either off-center when its length changes or extends beyond the borders of the bar.
Here's how it appears with my current CSS:
.bar{
position: relative;
background: #1DA598;
height: 96px;
width: 16px;
border: 1px solid #333;
margin-top: 72px;
margin-left: 24px;
}
.barFiller{
width: 100%;
height: 90%;
transition: width .2s ease-in;
}
.barText{
position: absolute;
bottom: 50%;
top: 50%;
width: 100%;
transform: rotate(-90deg);
color: "white"
}
Both barFiller and barText are children elements of the bar.
Even setting margins to auto and adjusting top, left, right, and bot values to 0 did not yield satisfactory results. Are there any other alternatives? The text should be centered regardless of the number of digits displayed on the progress bar.