Ezek
Ezek

Reputation: 151

HTML5 slider bar's thumb can't cover the track

I made a slider bar with html5 & css, like this.

function showValue(value) {
  document.getElementById("range").innerHTML = value;
}
.c-zoombar {
  -webkit-appearance: none;
  background: none;
  outline: none;
  overflow: hidden;
  width: 200px;
  height: 20px;
}
.c-zoombar::-webkit-slider-thumb {
  -webkit-appearance: none;
  background: #5e6fd9;
  border: 1px solid #fff;
  border-radius: 50%;
  height: 12px;
  position: relative;
  top: -5.5px;
  transition: .2s;
  width: 12px;
}
.c-zoombar::-webkit-slider-runnable-track {
  background: transparent;
  border: 1px solid #000;
  border-radius: 2px;
  cursor: pointer;
  height: 3px;
  width: 100%;
}
.c-zoombar:active::-webkit-slider-thumb {
  height: 16px;
  top: -8px;
  width: 16px;
}
.c-zoombar::-webkit-slider-thumb:hover {
  height: 16px;
  top: -8px;
  width: 16px;
}
<div>
  <input type="range" value="0" class="c-zoombar" onInput="showValue(this.value)" />
</div>
<div>
  <span id="range">0</span>
</div>

However, when I scroll the thumb to the most right/left, the thumb can't totally cover the track, as you can see in the following image. enter image description here

What should I modify to make the thumb be able to cover the track when scrolling to the most right/left? Thank you.

Upvotes: 3

Views: 951

Answers (1)

godblessstrawberry
godblessstrawberry

Reputation: 5058

I found the transform: scale() could do the part of trick (also scale transitioned more smoothly then width/height). is that 12px size is mandatory?

function showValue(value) {
  document.getElementById("range").innerHTML = value;
}
.c-zoombar {
  -webkit-appearance: none;
  background: none;
  outline: none;
  overflow: visible;
  width: 200px;
  height: 20px;
}
.c-zoombar::-webkit-slider-thumb {
  -webkit-appearance: none;
  background: #5e6fd9;
  border: 1px solid #fff;
  border-radius: 50%;
  height: 12px;
  position: relative;
  top: -5.5px;
  transition: .2s;
  width: 12px;
  transform: scale(1.33);
}
.c-zoombar::-webkit-slider-runnable-track {
  background: transparent;
  border: 1px solid #000;
  border-radius: 2px;
  cursor: pointer;
  height: 3px;
  width: 100%;

}
.c-zoombar:active::-webkit-slider-thumb,
.c-zoombar::-webkit-slider-thumb:hover {
  transform: scale(1.66);
}
<div class='wrap'>
  <input type="range" value="0" class="c-zoombar" onInput="showValue(this.value)" />
</div>
<div>
  <span id="range">0</span>
</div>

Upvotes: 1

Related Questions