I'm currently attempting to showcase a ::before
pseudo-element on a <progress>
bar in the form of a label featuring the value
attribute. My current approach successfully displays the ::before
element in Brave (v1.61.109), but unfortunately, it does not show up in Safari(17.1.2) and Firefox (121.0). Despite this, I am facing a challenge related to the height of the pseudo-element. It seems that the pseudo-element itself does not directly impact the layout flow. Nevertheless, I am eager to discover an effective workaround.
Moreover, besides just displaying the element, I aim for it to be factored into the height calculation of the parent box, specifically within the context of .card
. I am seeking a solution that adapts dynamically.
https://i.sstatic.net/7vjSf.jpg
Below is the provided HTML code:
<div class="card">
<p>Item 1</p>
<p>Item 2</p>
<progress max="100" value="100"></progress>
</div>
Additionally, here is the corresponding CSS:
.card {
display: flex;
flex-direction: column;
width: 300px;
background: beige;
}
progress[value] {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
border: none;
width: 100%;
}
progress {
position: relative;
}
progress:before {
content: attr(value) '% some text here';
font-size: 2rem;
color: black;
text-align: center;
height: 2rem;
line-height: normal;
}
progress[value]::-webkit-progress-value {
background-color: green;
border-radius: .2rem;
}
progress[value]::-moz-progress-bar {
background-color: green;
border-radius: .2rem;
}
If anyone has suggestions on how to address this visualization issue, please share your ideas!