#slider1 {
-webkit-appearance: slider-vertical; /* This makes ... */
background-color: black;
width: 1px;
height: 100px;
}
#slider2 {
-webkit-appearance: none; /* the difference. */
background-color: black;
width: 100px;
height: 1px;
}
#slider1::-webkit-slider-thumb,
#slider2::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 25px;
background: #04aa6d;
cursor: pointer;
}
#slider1::-webkit-slider-thumb:hover,
#slider2::-webkit-slider-thumb:hover {
width: 20px;
height: 20px;
}<input type="range" id="slider1" />
<input type="range" id="slider2" />
如图所示,除了-webkit-appearance属性之外,这两个滑块的CSS样式几乎相同。但是水平滑块(这是默认的滑块)接受样式,而垂直滑块拒绝它。我在使用Chrome。怎么让它起作用?谢谢!
发布于 2021-05-24 05:25:05
为了向范围滑块添加自定义样式,您需要设置一个css属性-webkit-appearance: none;,这是您在#2中做的,但是在# slider 1中却忽略了它。尝试以下代码
<input type="range" id="slider1" />
<input type="range" id="slider2" />
<style type="text/css">
#slider1 {
-webkit-appearance: none; /* This makes ... */
background-color: black;
width: 1px;
height: 100px;
}
#slider2 {
-webkit-appearance: none; /* the difference. */
background-color: black;
width: 100px;
height: 1px;
}
#slider1::-webkit-slider-thumb,
#slider2::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 25px;
background: #04aa6d;
cursor: pointer;
}
#slider1::-webkit-slider-thumb:hover,
#slider2::-webkit-slider-thumb:hover {
width: 20px;
height: 20px;
}
</style>然后你会发现垂直滑块
https://stackoverflow.com/questions/67666928
复制相似问题