首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为什么自定义CSS样式由于垂直滑块而不适用?

为什么自定义CSS样式由于垂直滑块而不适用?
EN

Stack Overflow用户
提问于 2021-05-24 05:08:48
回答 4查看 366关注 0票数 1

代码语言:javascript
复制
#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;
}
代码语言:javascript
复制
<input type="range" id="slider1" />
<input type="range" id="slider2" />

如图所示,除了-webkit-appearance属性之外,这两个滑块的CSS样式几乎相同。但是水平滑块(这是默认的滑块)接受样式,而垂直滑块拒绝它。我在使用Chrome。怎么让它起作用?谢谢!

EN

Stack Overflow用户

发布于 2021-05-24 05:25:05

为了向范围滑块添加自定义样式,您需要设置一个css属性-webkit-appearance: none;,这是您在#2中做的,但是在# slider 1中却忽略了它。尝试以下代码

代码语言:javascript
复制
<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>

然后你会发现垂直滑块

票数 0
EN
查看全部 4 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67666928

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档