using css. The result that I want to achieve is as follows: ...">

Input range of type css - background color

I want to configure <input type="range">using css. The result that I want to achieve is as follows:

but my next code gives me this

this is my code:

input[type='range'] {
    border-radius: 5px;
    height: 6px;
    vertical-align: middle;
    -webkit-appearance: none;
}
input[type="range"]::-moz-focus-inner:focus{   
    border : 0px;
    outline: 0;
} 
input[type='range']::-moz-range-track {
    border-radius: 5px;
    background-color: #E71D49;
    height: 6px;
    border: 1px dotted transparent !important;
}
input[type='range']::-webkit-slider-thumb {
    border-radius: 20px;
    background-color: #FFF;
    border:none;
    box-shadow: 0 5px #000;
    height: 5px;
    width: 5px;
}
input[type='range']::-moz-range-thumb {
    border-radius: 20px;
    background-color: #fff;
    border:none;
    height: 20px;
    box-shadow: 3px 2px 3px #000;
    width: 20px;
}

Is it possible to separate the slider from the "active" and "inactive"?

Thanks in advance Dario

+4
source share
2 answers

Hope this example helps you

Code: Example

var inputs = document.getElementsByTagName('input');
inputs = Array.splice(inputs, 0);
inputs.forEach(function (item) {
if (item.type === 'range') {
    item.onchange = function () {
        value = (item.value - item.min)/(item.max - item.min)
        item.style.backgroundImage = [
            '-webkit-gradient(',
              'linear, ',
              'left top, ',
              'right top, ',
              'color-stop(' + value + ', blue), ',
              'color-stop(' + value + ', red)',
            ')'
        ].join('');
    };
}
});
+4
source

I don't think this is possible with the default HTML range. If possible, you should take a look at the plugins that are customizable, I'm sure there are options that have exactly what you are looking for.

0
source

Source: https://habr.com/ru/post/1530934/


All Articles