input type range css - background color [duplicate]

为君一笑 提交于 2019-12-10 17:31:47

问题


I want to customize the <input type="range"> using css. The result I want to achieve is this:

but my following 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 into "active" and "inactive" one?

Thanks in advance Dario


回答1:


Hope the example will help 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('');
    };
}
});



回答2:


I don't believe this is possible with the default HTML range. If possible, you should look into plug-ins that are customisable, I am sure there are options out there that have exactly what you seek.



来源:https://stackoverflow.com/questions/22295498/input-type-range-css-background-color

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!