Search code examples
cssrangesliderion-range-slider

change color of ion range-slider handle


If I try to change the default color of ion range-slider (available here: https://github.com/IonDen/ion.rangeSlider) from red (default) to blue, like that:

.irs-slider.single {
    background: blue;
}

It becomes square:

enter image description here

(originally it looks like a thin red line: enter image description here)

What am I doing wrong?

DEMO

https://jsfiddle.net/chapkovski/xpvt214o/995048/

$(".js-range-slider").ionRangeSlider({
        type: "single",
        min: 0,
        max: 1000,
        from: 200,
        to: 500,
        grid: true
    });
.irs-slider.single {
    background: blue;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/ion-rangeslider/2.2.0/js/ion.rangeSlider.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/ion-rangeslider/2.2.0/css/ion.rangeSlider.css">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/ion-rangeslider/2.2.0/css/ion.rangeSlider.skinFlat.css">
<input type="text" class="js-range-slider" name="my_range" value="" />


Solution

  • The background is an image (https://cdnjs.cloudflare.com/ajax/libs/ion-rangeslider/2.2.0/img/sprite-skin-flat.png), so you cannot simply change the color. You can consider a gradient to create a similar image with the color you want. Since it's a simple line it should be easy.

    $(".js-range-slider").ionRangeSlider({
      type: "single",
      min: 0,
      max: 1000,
      from: 200,
      to: 500,
      grid: true
    });
    .irs-slider.single {
      background: linear-gradient(blue, blue) center/2px 100% no-repeat;
    }
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/ion-rangeslider/2.2.0/js/ion.rangeSlider.js"></script>
    <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/ion-rangeslider/2.2.0/css/ion.rangeSlider.css">
    <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/ion-rangeslider/2.2.0/css/ion.rangeSlider.skinFlat.css">
    <input type="text" class="js-range-slider" name="my_range" value="" />