0

I'm trying to style a range input to look like THIS

I have no idea how to style a range input to use own image as the thumb and make the line under the thumb thicker and bigger.

I did put a very basic example in this FIDDLE

Is it even possible to use own image for the range thumb and how would i go about making the line thicker and longer etc?

This is my CSS:

input[type=range] {
    -webkit-appearance: none;
    background-color: blue;
    width: 200px;
    height:20px;

}

input[type="range"]::-webkit-slider-thumb {
     -webkit-appearance: none;
    background-color: #666;
    opacity: 0.5;
    width: 10px;
    height: 26px;
    background-image:url('THUMB-ICON.png');
}

Any advise would be appreciated.

Getting somewhere I think: https://jsfiddle.net/BNm8j/5586/

Edit:

I made some changes to this but I don't know why the top of the thumb is missing?

https://jsfiddle.net/BNm8j/5588/

any ideas anyone?

Jackson
  • 800
  • 16
  • 36
  • Have a look at this answer and it may help you - http://stackoverflow.com/questions/34850327/styling-input-range-for-webkit-with-pure-css/34850882#34850882 – Harry May 23 '16 at 14:09
  • 1
    Add your input inside a div and add some padding to this div: https://jsfiddle.net/BNm8j/5589/ – trinaldi May 23 '16 at 14:16
  • @Tico, that did it mate. cheers. – Jackson May 23 '16 at 14:16

2 Answers2

0

here is the original CSS of the example link:

<div id="DIV_1">
    <div id="DIV_2">
    </div><a id="A_3"></a>
</div>

hope this helps you.

enter code here
#DIV_1 {
    box-sizing: border-box;
    color: rgb(92, 92, 92);
    float: left;
    height: 11px;
    overflow-wrap: break-word;
    position: relative;
    touch-action: none;
    width: 705px;
    word-wrap: break-word;
    column-rule-color: rgb(92, 92, 92);
    perspective-origin: 352.5px 5.5px;
    transform-origin: 352.5px 5.5px;
    background: rgb(222, 222, 222) none repeat scroll 0% 0% / auto padding-box border-box;
    border: 0px none rgb(92, 92, 92);
    border-radius: 3px 3px 3px 3px;
    font: normal normal normal normal 16px / normal Omnes, sans-serif;
    margin: 11px 30px 0px;
    outline: rgb(92, 92, 92) none 0px;
}/*#DIV_1*/

#DIV_2 {
    box-sizing: border-box;
    color: rgb(92, 92, 92);
    height: 11px;
    overflow-wrap: break-word;
    position: absolute;
    top: 0px;
    width: 122px;
    word-wrap: break-word;
    column-rule-color: rgb(92, 92, 92);
    perspective-origin: 61px 5.5px;
    transform-origin: 61px 5.5px;
    background: rgb(0, 143, 213) none repeat scroll 0% 0% / auto padding-box border-box;
    border: 0px none rgb(92, 92, 92);
    border-radius: 3px 3px 3px 3px;
    font: normal normal normal normal 16px / normal Omnes, sans-serif;
    outline: rgb(92, 92, 92) none 0px;
}/*#DIV_2*/

#A_3 {
    background-position: -65px 0px;
    box-sizing: border-box;
    color: rgb(247, 144, 47);
    cursor: default;
    display: block;
    height: 59px;
    left: 155px;
    overflow-wrap: break-word;
    position: absolute;
    text-decoration: none;
    top: -22px;
    touch-action: none;
    width: 58px;
    word-wrap: break-word;
    z-index: 100;
    column-rule-color: rgb(247, 144, 47);
    perspective-origin: 29px 29.5px;
    transform-origin: 29px 29.5px;
    background: rgba(0, 0, 0, 0) url("https://www.wonga.com/sites/all/themes/pizaz/images/mint/toolkit.png?v=2.2") no-repeat scroll -65px 0px / auto padding-box border-box;
    border: 0px none rgb(247, 144, 47);
    font: normal normal normal normal 16px / normal Omnes, sans-serif;
    margin: 0px 0px 0px -62px;
    outline: rgb(247, 144, 47) none 0px;
}/*#A_3*/
ilai
  • 126
  • 5
0

Here is a (hopefully) very ease to use tool to customize the style of <input> range:
https://toughengineer.github.io/demo/slider-styler

Here is an example:

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));
}
/*generated with Input range slider CSS style generator (version 20201223)
https://toughengineer.github.io/demo/slider-styler*/
input[type=range].styled-slider {
  height: 2.2em;
  -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 * 2em + var(--ratio) * (100% - 2em));
}

input[type=range].styled-slider:focus {
  outline: none;
}

/*webkit*/
input[type=range].styled-slider::-webkit-slider-thumb {
  width: 2em;
  height: 2em;
  border-radius: 1em;
  background: #007cf8;
  border: none;
  box-shadow: 0 0 2px black;
  margin-top: calc(max((1em - 1px - 1px) * 0.5,0px) - 2em * 0.5);
  -webkit-appearance: none;
}

input[type=range].styled-slider::-webkit-slider-runnable-track {
  height: 1em;
  border-radius: 0.5em;
  background: #efefef;
  border: 1px solid #b2b2b2;
  box-shadow: none;
}
input[type=range].styled-slider::-webkit-slider-thumb:hover {
  background: #0061c3;
}

input[type=range].styled-slider:hover::-webkit-slider-runnable-track {
  background: #e5e5e5;
  border-color: #9a9a9a;
}

input[type=range].styled-slider::-webkit-slider-thumb:active {
  background: #2f98f9;
}

input[type=range].styled-slider:active::-webkit-slider-runnable-track {
  background: #f5f5f5;
  border-color: #c1c1c1;
}

input[type=range].styled-slider.slider-progress::-webkit-slider-runnable-track {
  background: linear-gradient(#007cf8,#007cf8) 0/var(--sx) 100% no-repeat, #efefef;
}

input[type=range].styled-slider.slider-progress:hover::-webkit-slider-runnable-track {
  background: linear-gradient(#0061c3,#0061c3) 0/var(--sx) 100% no-repeat, #e5e5e5;
}

input[type=range].styled-slider.slider-progress:active::-webkit-slider-runnable-track {
  background: linear-gradient(#2f98f9,#2f98f9) 0/var(--sx) 100% no-repeat, #f5f5f5;
}

/*mozilla*/
input[type=range].styled-slider::-moz-range-thumb {
  width: 2em;
  height: 2em;
  border-radius: 1em;
  background: #007cf8;
  border: none;
  box-shadow: 0 0 2px black;
}

input[type=range].styled-slider::-moz-range-track {
  height: max(calc(1em - 1px - 1px),0px);
  border-radius: 0.5em;
  background: #efefef;
  border: 1px solid #b2b2b2;
  box-shadow: none;
}

input[type=range].styled-slider::-moz-range-thumb:hover {
  background: #0061c3;
}

input[type=range].styled-slider:hover::-moz-range-track {
  background: #e5e5e5;
  border-color: #9a9a9a;
}

input[type=range].styled-slider::-moz-range-thumb:active {
  background: #2f98f9;
}

input[type=range].styled-slider:active::-moz-range-track {
  background: #f5f5f5;
  border-color: #c1c1c1;
}

input[type=range].styled-slider.slider-progress::-moz-range-track {
  background: linear-gradient(#007cf8,#007cf8) 0/var(--sx) 100% no-repeat, #efefef;
}

input[type=range].styled-slider.slider-progress:hover::-moz-range-track {
  background: linear-gradient(#0061c3,#0061c3) 0/var(--sx) 100% no-repeat, #e5e5e5;
}

input[type=range].styled-slider.slider-progress:active::-moz-range-track {
  background: linear-gradient(#2f98f9,#2f98f9) 0/var(--sx) 100% no-repeat, #f5f5f5;
}

/*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: 2em;
  height: 2em;
  border-radius: 1em;
  background: #007cf8;
  border: none;
  box-shadow: 0 0 2px black;
  margin-top: 0;
  box-sizing: border-box;
}

input[type=range].styled-slider::-ms-track {
  height: 1em;
  border-radius: 0.5em;
  background: #efefef;
  border: 1px solid #b2b2b2;
  box-shadow: none;
  box-sizing: border-box;
}

input[type=range].styled-slider::-ms-thumb:hover {
  background: #0061c3;
}

input[type=range].styled-slider:hover::-ms-track {
  background: #e5e5e5;
  border-color: #9a9a9a;
}

input[type=range].styled-slider::-ms-thumb:active {
  background: #2f98f9;
}

input[type=range].styled-slider:active::-ms-track {
  background: #f5f5f5;
  border-color: #c1c1c1;
}

input[type=range].styled-slider.slider-progress::-ms-fill-lower {
  height: max(calc(1em - 1px - 1px),0px);
  border-radius: 0.5em 0 0 0.5em;
  margin: -1px 0 -1px -1px;
  background: #007cf8;
  border: 1px solid #b2b2b2;
  border-right-width: 0;
}

input[type=range].styled-slider.slider-progress:hover::-ms-fill-lower {
  background: #0061c3;
  border-color: #9a9a9a;
}

input[type=range].styled-slider.slider-progress:active::-ms-fill-lower {
  background: #2f98f9;
  border-color: #c1c1c1;
}
ordinary slider:<br />
<input type="range" class="styled-slider" style="width: 20em;" /><br />
slider with progress styling (made it slightly longer):<br />
<input type="range" class="styled-slider slider-progress" style="width: 30em;" />
paul
  • 448
  • 4
  • 11