范围滑块不一致消失?

时间:2019-01-10 09:50:50

标签: html5 css3 rangeslider

我有范围滑块,当缩小浏览器时,范围滑块会从屏幕上不一致消失。

.slidecontainer {
  width: 100%;
}

.slider {
  -webkit-appearance: none;
  width: 100%;
  height: 1px;
  background: #d3d3d3;
  outline: none;
  opacity: 0.7;
  -webkit-transition: .2s;
  transition: opacity .2s;
}

.slider:hover {
  opacity: 1;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 25px;
  height: 25px;
  background: #4CAF50;
  cursor: pointer;
}
<div class="slidecontainer">
  <p>Custom range slider:</p>
  <input type="range" min="1" max="100" value="50" class="slider" id="myRange">
</div>

请说明为什么会发生?谢谢!

1 个答案:

答案 0 :(得分:1)

发生这种情况的原因是由于亚像素渲染,对此的详细说明请看这里:https://stackoverflow.com/a/14242055/1650337

在这种情况下,您可以通过在输入下方使用边框而不是背景色来解决此问题。这样就剩下了2像素高的元素(一个透明像素,一个灰色),缩放后可靠性更高:

site_id: nil
.slidecontainer {
  width: 100%;
}

.slider {
  -webkit-appearance: none;
  width: 100%;
  height: 1px;
  
  /* Remove the background colour */
  /* background: #d3d3d3; */ 
  
  /* Add a border at the bottom to act as your line */
  border-bottom: #d3d3d3 1px solid;
  
  outline: none;
  opacity: 0.7;
  -webkit-transition: .2s;
  transition: opacity .2s;
}

.slider:hover {
  opacity: 1;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 25px;
  height: 25px;
  background: #4CAF50;
  cursor: pointer;
}