【发布时间】:2020-11-03 23:04:47
【问题描述】:
我正在使用 HTML5 输入范围,我需要设置滑块的样式,使其具有不同的颜色 (black) 和宽度(2px) 直到滑块的位置,并将其设置为#393837 和 1px 在滑块之后。
为了说明下图,它之前更暗更厚,之后更薄:
到目前为止,我所取得的成就是,在整个滑块中都有#393837 的颜色。
.slider {
width: 100%;
height: 1px;
outline: none;
background: #393837;
-webkit-appearance: none;
}
.slider::-webkit-slider-thumb {
width: 8px;
height: 8px;
cursor: pointer;
appearance: none;
background: black;
border-radius: 50%;
-webkit-appearance: none;
}
.slider::-moz-range-thumb {
width: 8px;
height: 8px;
border: none;
cursor: pointer;
border-radius: 50%;
background: black;
}
<input min="1" max="100" type="range" className="slider" />
附:我正在使用 reactJS,所以我不想使用 jQuery
注意:我的问题已被标记为重复,但other question 中的解决方案对输入元素使用硬编码宽度,而我没有。
【问题讨论】:
-
dev.to/christo_pr/… 一篇博文使用
<datalist id="custom-list">和<input type="range" list="custom-list"/>解决了这个问题 -
@GrzegorzT。不,这不是因为它使用硬编码值作为输入范围的
width。 -
@VinaySharma 我检查了它,该答案中的解决方案也可以在没有提供固定宽度的情况下工作
-
不要用大写字母写它没有帮助。看看这个插件react-input-range
标签: javascript html css reactjs input