given this input
.prettyRange {
-webkit-appereance: none;
}
.prettyRange::-webkit-slider-runnable-track {
background: -webkit-linear-gradient(right, #fff 0%, green 50%, #fff 0%);
}
<input class="prettyRange" type="range" name="capability" data-percent="100%">
But if i'm trying to set the % via attr(data-percent) it doesn't work.
background: -webkit-linear-gradient(right, #fff 0%, green attr(data-percent), #fff 0%)
How can I use the data-percent property of the item?
PS: I want to use the data-property because I need to update this value using JS and we cannot select pseudo-elements with JS.
An alternative is to use CSS variable that you can easily adjust with JS:
.prettyRange {
-webkit-appereance: none;
}
.prettyRange::-webkit-slider-runnable-track {
background: -webkit-linear-gradient(right,#fff 0%,green var(--p,50%), #fff 0%);
}
<input class="prettyRange" type="range" name="capability" style="--p:80%">
<br>
<input class="prettyRange" type="range" name="capability" style="--p:100%">
<br>
<input class="prettyRange" type="range" name="capability" >
Using JS to change the value:
document.querySelector('.prettyRange').addEventListener('input',function(e) {
e.target.style.setProperty('--p', e.target.value*10+'%');
})
.prettyRange {
-webkit-appereance: none;
}
.prettyRange::-webkit-slider-runnable-track {
background: -webkit-linear-gradient(right, #fff 0%, green var(--p, 50%), #fff 0%);
}
<input class="prettyRange" min='1' max='10' type="range" name="capability">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With