JSFiddle - React, Tailwind, and code Playground
HTML
<span id="wsite-nav-cart-num">99</span>
CSS
/* desk boxes*/
.desk_box_ver{
width: 18px;
height: 33px;
margin:10px;
}
.desk_box_ver:hover{
cursor: pointer;
}
.desk_box_hor{
width: 23px;
height: 10px;
}
.desk_box_hor:hover{
cursor: pointer;
}
#wsite-nav-cart-num {
color: #fff !important;
margin: 0px -2px 0px -3px;
font-family: 'futura lt' !important;
font-size: 10.5px;
font-weight: normal;
letter-spacing: .2px;
width: auto;
text-indent: 0px;
line-height: 10px;
padding: 3px 5px 3px 5px !important;
top: 5px;
border-radius: 100%;
z-index: 99999999999;
height: auto;
right: 10px;
text-align: center;
}
JavaScript
function colorCode(num, opts) {
var color = [];
if(num <= opts.start.number)
color = opts.start.color;
else if(num >= opts.end.number)
color = opts.end.color;
else {
for(var i = 0; i < 3; i++) {
color[i] = Math.round( (num - opts.start.number) / (opts.end.number - opts.start.number) * (opts.end.color[i] - opts.start.color[i]) + opts.start.color[i] );
}
}
return 'rgb(' + color.join() + ')';
}
$('span#wsite-nav-cart-num').each(function() {
$(this).css('background-color', colorCode(+$(this).text(), {
start: {number: 0, color: [171,171,171]},
end: {number: 1, color: [200,181,0]}
}));
});