1

I have range slider, when zoom-out the browser the range slider will get disappear inconsistently from the screen.

.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>

Please suggest why its happening? Thanks!

DBS
  • 9,110
  • 4
  • 35
  • 53
Rijo
  • 2,963
  • 5
  • 35
  • 62
  • 1
    Do you mean the line behind the slider? or the slider draggable part? I can see the lines disappearing (due to sub pixel rendering, see: https://stackoverflow.com/a/14242055/1650337 ) is that what you're asking about? – DBS Jan 10 '19 at 13:57
  • If you want to overcome this you need to have a larger bar : https://jsfiddle.net/cnfdy8zx/1/ – Alexandre Elshobokshy Jan 10 '19 at 14:54
  • Can't integrate on height:1px, it's possible on Firefox but not in chrome. As per my design I can't increase the line height – Rijo Jan 11 '19 at 02:16
  • @dbs I mean the line – Rijo Jan 11 '19 at 02:18

1 Answers1

1

The reason this is happening is due to subpixel rendering, for a good explanation of that have a look here: https://stackoverflow.com/a/14242055/1650337

In your case you can work around this by using a border below your input, rather than a background colour. This leaves you with a 2 pixel high element (One transparent pixel, one grey) which is a lot more reliable when scaled:

.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;
}
<div class="slidecontainer">
  <p>Custom range slider:</p>
  <input type="range" min="1" max="100" value="50" class="slider" id="myRange">
</div>
DBS
  • 9,110
  • 4
  • 35
  • 53