我尝试将范围输入设置为THIS
我不知道如何设置范围输入的样式以使用自己的图像作为拇指,并使拇指下的线条更粗更大。
我确实在这个FIDDLE
中放了一个非常基本的例子甚至可以将自己的图像用于范围拇指,我将如何使线条更粗更长等?
这是我的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');
}
任何建议都将不胜感激。
到达某个地方我想:https://jsfiddle.net/BNm8j/5586/
修改
我对此做了一些修改,但我不知道为什么拇指顶部缺失?
https://jsfiddle.net/BNm8j/5588/
任何想法?
答案 0 :(得分:0)
这是示例链接的原始CSS:
<div id="DIV_1">
<div id="DIV_2">
</div><a id="A_3"></a>
</div>
希望这会对你有所帮助。
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*/
答案 1 :(得分:0)
这是一个(希望如此)非常易于使用的工具来自定义 <input>
范围的样式:
https://toughengineer.github.io/demo/slider-styler
这是一个例子:
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;" />