"How to make the left side of a range slider a different color than the right side of the slider?"
Bootstrap 3.3.0 Snippet by muhittinbudak

<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <!------ Include the above in your HEAD tag ----------> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Strait"> <div class="container" style="font-family: 'Strait', sans-serif;"> <div class="row"> <h2>Slider range (Costumize bg colors)</h2> <input type="range" id="myRange" min="1" max="100" value="18" step="1" class="slider styled-slider slider-progress" > <br> <div class="well" style="border-color: red;"><center class="h1">% <span id="slider_value">18</span></center></div> </div> </div>
/*generated with Input range slider CSS style generator (version 20201223) https://toughengineer.github.io/demo/slider-styler*/ input[type=range].styled-slider { height: 2.8em; -webkit-appearance: none; } /*progress support*/ input[type=range].styled-slider.slider-progress { --range: calc(var(--max) - var(--min)); --ratio: calc((var(--value) - var(--min)) / var(--range)); --sx: calc(0.5 * 2.8em + var(--ratio) * (100% - 2.8em)); } input[type=range].styled-slider:focus { outline: none; } /*webkit*/ input[type=range].styled-slider::-webkit-slider-thumb { width: 2.8em; height: 2.8em; border-radius: 1.4em; background: #1381A9; border: 0.3em solid #21404D; box-shadow: none; margin-top: calc(1em * 0.5 - max(2.8em * 0.5,0.3em)); -webkit-appearance: none; } input[type=range].styled-slider::-webkit-slider-runnable-track { height: 1em; border-radius: 0.5em; background: #D0D0D0; border: none; box-shadow: none; } input[type=range].styled-slider::-webkit-slider-thumb:hover { background: #0E6180; } input[type=range].styled-slider:hover::-webkit-slider-runnable-track { background: #A8A8A8; } input[type=range].styled-slider::-webkit-slider-thumb:active { background: #18A5D9; } input[type=range].styled-slider:active::-webkit-slider-runnable-track { background: #DBDBDB; } input[type=range].styled-slider.slider-progress::-webkit-slider-runnable-track { background: linear-gradient(#FF0000,#FF0000) 0/var(--sx) 100% no-repeat, #D0D0D0; } input[type=range].styled-slider.slider-progress:hover::-webkit-slider-runnable-track { background: linear-gradient(#8E0F0F,#8E0F0F) 0/var(--sx) 100% no-repeat, #A8A8A8; } input[type=range].styled-slider.slider-progress:active::-webkit-slider-runnable-track { background: linear-gradient(#18A5D9,#18A5D9) 0/var(--sx) 100% no-repeat, #DBDBDB; } /*mozilla*/ input[type=range].styled-slider::-moz-range-thumb { width: max(calc(2.8em - 0.3em - 0.3em),0px); height: max(calc(2.8em - 0.3em - 0.3em),0px); border-radius: 1.4em; background: #1381A9; border: 0.3em solid #21404D; box-shadow: none; } input[type=range].styled-slider::-moz-range-track { height: 1em; border-radius: 0.5em; background: #D0D0D0; border: none; box-shadow: none; } input[type=range].styled-slider::-moz-range-thumb:hover { background: #0E6180; } input[type=range].styled-slider:hover::-moz-range-track { background: #A8A8A8; } input[type=range].styled-slider::-moz-range-thumb:active { background: #18A5D9; } input[type=range].styled-slider:active::-moz-range-track { background: #DBDBDB; } input[type=range].styled-slider.slider-progress::-moz-range-track { background: linear-gradient(#FF0000,#FF0000) 0/var(--sx) 100% no-repeat, #D0D0D0; } input[type=range].styled-slider.slider-progress:hover::-moz-range-track { background: linear-gradient(#8E0F0F,#8E0F0F) 0/var(--sx) 100% no-repeat, #A8A8A8; } input[type=range].styled-slider.slider-progress:active::-moz-range-track { background: linear-gradient(#18A5D9,#18A5D9) 0/var(--sx) 100% no-repeat, #DBDBDB; } /*ms*/ input[type=range].styled-slider::-ms-fill-upper { background: transparent; border-color: transparent; } input[type=range].styled-slider::-ms-fill-lower { background: transparent; border-color: transparent; } input[type=range].styled-slider::-ms-thumb { width: 2.8em; height: 2.8em; border-radius: 1.4em; background: #1381A9; border: 0.3em solid #21404D; box-shadow: none; margin-top: 0; box-sizing: border-box; } input[type=range].styled-slider::-ms-track { height: 1em; border-radius: 0.5em; background: #D0D0D0; border: none; box-shadow: none; box-sizing: border-box; } input[type=range].styled-slider::-ms-thumb:hover { background: #0E6180; } input[type=range].styled-slider:hover::-ms-track { background: #A8A8A8; } input[type=range].styled-slider::-ms-thumb:active { background: #18A5D9; } input[type=range].styled-slider:active::-ms-track { background: #DBDBDB; } input[type=range].styled-slider.slider-progress::-ms-fill-lower { height: 1em; border-radius: 0.5em 0 0 0.5em; margin: -undefined 0 -undefined -undefined; background: #FF0000; border: none; border-right-width: 0; } input[type=range].styled-slider.slider-progress:hover::-ms-fill-lower { background: #8E0F0F; } input[type=range].styled-slider.slider-progress:active::-ms-fill-lower { background: #18A5D9; }
$(document).ready(function(){ //------ range input values start for (let e of document.querySelectorAll('input[type="range"].slider-progress')) { e.style.setProperty('--value', e.value); e.style.setProperty('--min', e.min == '' ? '0' : e.min); e.style.setProperty('--max', e.max == '' ? '100' : e.max); e.addEventListener('input', () => e.style.setProperty('--value', e.value)); } //------ range input values end //--- range change function start $(document).on('input change', '#myRange', function() { $('#slider_value').html( $(this).val() ); }); //--------range change fucntion end });

Related: See More


Questions / Comments: