Styling input range for webkit with pure CSS - css

I would like to customize input type range like this.
I tried to use the following code to change the thumb and as below but selected range color is not changed.
HTML:
<input type="range" />
CSS:
input[type=range]::-webkit-slider-thumb {
-webkit-appearance: none;
height: 20px;
width: 20px;
border-radius: 10px;
background: red;
cursor: pointer;
border: none;
margin-top: -8px;
}
input[type=range] {
-webkit-appearance: none;
outline: 0;
margin: 0;
padding: 0;
height: 30px;
width: 100%;
}
Could anybody please suggest me to change the selected runnable track background color?

Interesting approach being used by the Ionic framework for styling the range input track with just CSS. They are adding a ::before pseudo-element to the ::-webkit-slider-thumb, making it as wide as possible and then positioning it on top of the track. (I couldn't get border-radius to work with it.)
input[type='range'] {
width: 210px;
height: 30px;
overflow: hidden;
cursor: pointer;
}
input[type='range'],
input[type='range']::-webkit-slider-runnable-track,
input[type='range']::-webkit-slider-thumb {
-webkit-appearance: none;
}
input[type='range']::-webkit-slider-runnable-track {
width: 200px;
height: 10px;
background: #AAA;
}
input[type='range']::-webkit-slider-thumb {
position: relative;
height: 30px;
width: 30px;
margin-top: -10px;
background: steelblue;
border-radius: 50%;
border: 2px solid white;
}
input[type='range']::-webkit-slider-thumb::before {
position: absolute;
content: '';
height: 10px; /* equal to height of runnable track */
width: 500px; /* make this bigger than the widest range input element */
left: -502px; /* this should be -2px - width */
top: 8px; /* don't change this */
background: #777;
}
<div class="container">
<input type="range" min="0" max="100" value="10" />
</div>
As far as I am aware there is no pure CSS way to do this for Webkit powered browsers (and FF). IE provides a way to style the two portions of the track using -ms-fill-lower and -ms-fill-upper but there are no equivalents in WebKit and hence JavaScript will be needed.
You could use a linear-gradient as background image for the runnable track and then change the background-size using JavaScript to achieve the required effect. As question is specific to Webkit, the snippet provided currently works only in Webkit powered browsers. This method does allow us to add a border-radius to the track.
This snippet was adapted from Ana Tudor's CodePen Demo. That demo has ways to make it work in other browsers also.
window.onload = function() {
var input = document.querySelector('input[type=range]'),
style_el = document.createElement('style'),
styles = [],
track_sel = ['::-webkit-slider-runnable-track'];
document.body.appendChild(style_el);
styles.push('');
input.addEventListener('input', function() {
var min = this.min || 0,
max = this.max || 100,
c_style, u, edge_w, val, str = '';
this.setAttribute('value', this.value);
val = this.value + '% 100%';
str += 'input[type="range"]' + track_sel[0] + '{background-size:' + val + '}';
styles[0] = str;
style_el.textContent = styles.join('');
}, false);
}
input[type='range'] {
width: 210px;
height: 50px;
cursor: pointer;
}
input[type='range'],
input[type='range']::-webkit-slider-runnable-track,
input[type='range']::-webkit-slider-thumb {
-webkit-appearance: none;
}
input[type='range']::-webkit-slider-runnable-track {
width: 200px;
height: 10px;
background: linear-gradient(to right, #777, #777), #AAA;
background-size: 10% 100%;
background-repeat: no-repeat;
border-radius: 5px;
}
input[type='range']::-webkit-slider-thumb {
height: 30px;
width: 30px;
margin-top: -10px;
background: steelblue;
border-radius: 50%;
border: 2px solid white;
}
<div class="container">
<input type="range" min="0" max="100" value="10" />
</div>

I got a solution that does not use a style tag but css variable:
const input = document.querySelector("input");
function setBackgroundSize(input) {
input.style.setProperty("--background-size", `${getBackgroundSize(input)}%`);
}
setBackgroundSize(input);
input.addEventListener("input", () => setBackgroundSize(input));
function getBackgroundSize(input) {
const min = +input.min || 0;
const max = +input.max || 100;
const value = +input.value;
const size = (value - min) / (max - min) * 100;
return size;
}
input[type='range'] {
width: 400px;
}
input[type='range'],
input[type='range']::-webkit-slider-runnable-track,
input[type='range']::-webkit-slider-thumb {
-webkit-appearance: none;
}
input[type='range']::-webkit-slider-runnable-track {
height: 3px;
background: linear-gradient(to right, #293043, #293043), #D7D7D7;
background-size: var(--background-size, 0%) 100%;
background-repeat: no-repeat;
border-radius: 5px;
}
input[type='range']::-webkit-slider-thumb {
width: 15px;
height: 15px;
cursor: pointer;
background: #293043;
border: solid white 1px;
border-radius: 50%;
margin-top: -6px;
box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.4);
}
/** FF*/
input[type="range"]::-moz-range-progress {
background-color: #293043;
border-radius: 5px;
}
input[type="range"]::-moz-range-track {
background-color: #D7D7D7;
border-radius: 5px;
}
input[type="range"]::-moz-range-thumb {
width: 15px;
height: 15px;
cursor: pointer;
background: #293043;
border: solid white 1px;
border-radius: 50%;
margin-top: -6px;
box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.4);
}
<input type="range" min="5" max="95" step="1" value="15">
This works on Chrome and Firefox :).

Related

Floating labels - label above input field

I'm working on an existing form, where I want to introduce floating labels.
A lot of the solutions I have seen on stack overflow are great, but require the label tag, to sit directly underneath the <input> tag. For example here.
On the form I'm working on though, my label tag, sits above the <input> tag. And the input tag, sits in a seperate div. (I am not allowed to move these tags around - please don't ask, restriction of the application!).
Is there anyway, I can achieve floating CSS labels, with this structure?
.test-field {
clear: both;
margin-bottom: 20px;
position: relative;
}
.test-field__input {
font-size: 0.875em;
line-height: 1;
-moz-appearance: none;
-webkit-appearance: none;
background-color: #f5f5f5;
border: 2px solid #eee;
border-radius: 4px;
color: grey;
height: calc((40 / 14) * 1em);
line-height: 1;
outline: 0;
padding: 0 8px;
vertical-align: top;
width: 100%;
}
/* // FOCUS */
.test-field__input:focus,
.test-field__input ~ input:checked:focus {
border-color: #5d7199;
}
/* // DISABLED */
.test-field--disabled .test-field__input {
background-color: #e8e8e3;
cursor: not-allowed;
}
.test-field--disabled .test-field__flag, .test-field--disabled .test-field__label {
color: #d0d0cb;
}
/* // ERROR */
.test-field--error .test-field__input, .test-field--error .test-field__selection .atc-field__input {
border-color: #ff4436;
color: #ff4436;
}
/* // FLOATING LABEL */
.test-field--floating .test-field-input {
position: relative;
margin-bottom: 1.5rem;
}
.test-field__label {
position: absolute;
top: 0;
padding: 7px 0 0 13px;
transition: all 200ms;
opacity: 0.5;
}
.test-field__input:focus + .test-field__label,
.test-field--floating .test-field__input:valid + .test-field__label {
font-size: 75%;
transform: translate3d(0, -100%, 0);
opacity: 1;
}
<div class="test-field test-field--floating">
<label for="a" class="test-field__label">Input label</label>
<input class="test-field__input" id="b" type="text" value="" required>
</div>
This seemed to be a good way to replicate floating labels, with a similar DOM structure:
const floatField = document.querySelectorAll('.ej-form-field-input-textbox');
const floatContainer = document.querySelectorAll('.ej-form-field');
for (let i = 0; i < floatField.length; i++) {
floatField[i].addEventListener('focus', () => {
floatContainer[i].classList.add('active');
});
};
for (let i = 0; i < floatField.length; i++) {
floatField[i].addEventListener('blur', () => {
floatContainer[i].classList.remove('active');
});
};
.ej-form-field {
border: solid 1px #ccc;
padding: 0 8px;
position: relative;
}
.ej-form-field input {
border: 1px solid red;
font-size: 16px;
outline: 0;
height: 30px;
/* padding: 16px 0 10px; */
}
label {
font-size: 16px;
position: absolute;
transform-origin: top left;
transform: translate(0, 16px) scale(1);
transition: all .1s ease-in-out;
height: 40px;
}
.ej-form-field.active label {
transform: translate(0, -6px) scale(.95);
color: red;
margin-left: 10px;
background-color: #fff;
border: 1px solid green;
height: 20px;
}
<div id="floatContainer" class="ej-form-field">
<label for="floatField">First name</label>
<div>
<input id="floatField" class="ej-form-field-input-textbox" type="text">
</div>
</div>
<div id="floatContainer" class="ej-form-field">
<label for="floatField">Last name</label>
<div>
<input id="floatField" class="ej-form-field-input-textbox" type="text">
</div>
</div>

Button not laid out against top of relatively positioned container in Firefox

I'm building a toggle switch and the head (button) isn't positioned all the way to the top as I'd expect it to be in Firefox. Works fine in Chrome, so maybe has something to do with default browser styles?
Edit: I know how to make it work, I want to know why it happens.
codepen https://codepen.io/warhammered_cat/pen/qBZYZVy
const toggleSwitch = document.querySelector('.toggle-switch')
const toggleSwitchHead = document.querySelector('.head')
function handleToggle(e) {
toggleSwitch.classList.toggle('active')
}
toggleSwitchHead.addEventListener('click', handleToggle)
* {
box-sizing: border-box;
}
document, body {
margin: 0;
padding: 0;
}
.head {
width: 1.25rem;
height: 1.25rem;
border: 0.125rem solid gray;
border-radius: 50%;
background-color: white;
cursor: pointer;
transition: all 0.4s;
outline: none;
box-shadow: none;
}
.rail {
height: 0.75rem;
width: 100%;
background-color: gray;
border: 0.125rem solid gray;
position: absolute;
top: 0.25rem;
z-index: -1;
border-radius: 0.3rem;
transition: all 0.4s;
}
.toggle-switch {
position: relative;
height: 1.25rem;
width: 2rem;
}
.toggle-switch.active > .head {
background-color: #F7941E;
border-color: #F7841E;
transform: translateX(1rem);
}
.toggle-switch.active > .rail {
border: 0.125rem solid #F7941E;
background-color: white;
}
<div class='toggle-switch'>
<button class='head'></button>
<div class='rail'></div>
</div>
The <button> element is what is specifically being rendered differently in Firefox and Chrome.
If you change the <button> to a <div> the problem fixes itself.
The reason is that the button element is not a block element by default. You have to explicitly set the button to be a block element to get the desired behavior.
.head {
...
display: block;
...
}
try this instead,
Add display:inline-flex; to head class
.head{
display:inline-flex;
}
Click below to see codepen demo
Result :
const toggleSwitch = document.querySelector('.toggle-switch')
const toggleSwitchHead = document.querySelector('.head')
function handleToggle(e) {
toggleSwitch.classList.toggle('active')
}
toggleSwitchHead.addEventListener('click', handleToggle)
* {
box-sizing: border-box;
}
document, body {
margin: 0;
padding: 0;
}
.head {
width: 1.25rem;
height: 1.25rem;
border: 0.125rem solid gray;
border-radius: 50%;
background-color: white;
cursor: pointer;
transition: all 0.4s;
outline: none;
box-shadow: none;
display:inline-flex;
}
.rail {
height: 0.75rem;
width: 100%;
background-color: gray;
border: 0.125rem solid gray;
position: absolute;
top: 0.25rem;
z-index: -1;
border-radius: 0.3rem;
transition: all 0.4s;
}
.toggle-switch {
position: relative;
height: 1.25rem;
width: 2rem;
}
.toggle-switch.active > .head {
background-color: #F7941E;
border-color: #F7841E;
transform: translateX(1rem);
}
.toggle-switch.active > .rail {
border: 0.125rem solid #F7941E;
background-color: white;
}
<div class='toggle-switch'>
<button class='head'></button>
<div class='rail'></div>
</div>

How to display value inside the Range Slider?

range slider design
Hello,
I need help creating this range slider. I need the value to be displayed on or inside the slider, not on a tooltip or bubble over it. And the left side with a different color than the right side.
I have found a way to make the value on the slider but can't apply any style on it!
Any help is very appreciated.
Thank you!
$("document").ready(function() {
$(".slider").rangeslider();
});
$.fn.rangeslider = function(options) {
this.each(function(i, elem) {
var obj = $(elem); // input element
var defautValue = obj.attr("value");
var slider_max = (obj.attr("max"));
var slider_min = (obj.attr("min"));
var slider_step = (obj.attr("step"));
var slider_stop = (slider_max - slider_min) / slider_step;
var step_percentage = 100 / slider_stop;
console.log(step_percentage);
var color = "";
var classlist = obj.attr("class").split(/\s+/);
$.each(classlist, function(index, item) {
if (item.startsWith('slider-')) {
color = item;
}
});
if (color == "") {
color = "slider-blue";
}
if (slider_stop <= 30) {
var i;
var dots = "";
for (i = 1; i < slider_stop; i++) {
dots += "<div class='dot' id='" + i + "' style='left:" + step_percentage * i + "%;'></div>";
}
} else {
var dots = "";
}
obj.wrap("<span class='slider " + color + "'></span>");
obj.after("<span class='slider-container " + color + "'><span class='bar'><span></span>" + dots + "</span><span class='bar-btn'><span>0</span></span></span>");
obj.attr("oninput", "updateSlider(this)");
updateSlider(this);
return obj;
});
};
function updateSlider(passObj) {
var obj = $(passObj);
var value = obj.val();
var min = obj.attr("min");
var max = obj.attr("max");
var range = Math.round(max - min);
var percentage = Math.round((value - min) * 100 / range);
var nextObj = obj.next();
var btn = nextObj.find("span.bar-btn");
if (value == min) {
nextObj.find("span.bar-btn").css("left", percentage + "%");
} else if (value == max) {
nextObj.find("span.bar-btn").css("left", "calc(" + percentage + "% - " + btn.width() + "px");
} else {
nextObj.find("span.bar-btn").css("left", "calc(" + percentage + "% - " + btn.width() / 2 + "px");
}
nextObj.find("span.bar > span").css("width", percentage + "%");
nextObj.find("span.bar-btn > span").text(value);
};
body {
font-family: Calibri;
background-image: linear-gradient(90deg, #691337, #613374, #133742);
}
.heading {
text-align: center;
color: #fff;
}
.wrap {
margin: 25px;
background: #133742;
border-radius: 7.5px;
padding: 5px 0px 20px 53px;
}
/* SLIDER-STYLES */
.slider-orange>.bar>span {
transition: 0.3s;
background: #ff821e!important;
}
.slider-orange>.bar-btn {
background: #ff821e!important;
border: 2px solid #ffbf8c !important;
transition: 0.3s;
}
.slider-orange:hover>input+.slider-container>.bar-btn {
box-shadow: inset 0 0 2px #ff821e;
color: #ff821e;
background: #fff !important;
border: 2px solid #ff821e !important;
}
.slider-red>.bar>span {
transition: 0.3s;
background: #eb0041!important;
}
.slider-red>.bar-btn {
background: #eb0041!important;
border: 2px solid #f9b2c6 !important;
transition: 0.3s;
}
.slider-red:hover>input+.slider-container>.bar-btn {
box-shadow: inset 0 0 2px #eb0041;
color: #eb0041;
background: #fff !important;
border: 2px solid #eb0041 !important;
}
.slider-green>.bar>span {
transition: 0.3s;
background: #00965a!important;
}
.slider-green>.bar-btn {
background: #00965a!important;
border: 2px solid #b2dfcd !important;
transition: 0.3s;
}
.slider-green:hover>input+.slider-container>.bar-btn {
box-shadow: inset 0 0 2px #00965a;
color: #00965a;
background: #fff !important;
border: 2px solid #00965a !important;
}
.slider-yellow>.bar>span {
transition: 0.3s;
background: #ffd200!important;
}
.slider-yellow>.bar-btn {
background: #ffd200!important;
border: 2px solid #fff1b2 !important;
transition: 0.3s;
}
.slider-yellow:hover>input+.slider-container>.bar-btn {
box-shadow: inset 0 0 2px #ffd200;
color: #1d1d1b;
background: #fff !important;
border: 2px solid #ffd200 !important;
}
.slider-cyan>.bar>span {
transition: 0.3s;
background: #00b4e6!important;
}
.slider-cyan>.bar-btn {
background: #00b4e6!important;
border: 2px solid #b2e8f7 !important;
transition: 0.3s;
}
.slider-cyan:hover>input+.slider-container>.bar-btn {
box-shadow: inset 0 0 2px #00b4e6;
color: #00b4e6;
background: #fff !important;
border: 2px solid #00b4e6 !important;
}
.slider-blue>.bar>span {
transition: 0.3s;
background: #0014a0!important;
}
.slider-blue>.bar-btn {
background: #0014a0!important;
border: 2px solid #0014a0 !important;
transition: 0.3s;
}
.slider-blue:hover>input+.slider-container>.bar-btn {
box-shadow: inset 0 0 2px #0014a0;
color: #0014a0;
background: #fff !important;
border: 2px solid #0014a0 !important;
}
.dot {
width: 7px !important;
height: 7px;
background: #fff;
display: block;
position: absolute;
border-radius: 125%;
top: 2px;
}
.slider {
display: inline-block;
width: 100%;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
position: relative;
}
.slider>input {
opacity: 0;
width: 100%;
height: 40px;
position: relative;
z-index: 5;
-webkit-appearance: none;
}
.slider>input::-webkit-slider-thumb {
-webkit-appearance: none;
z-index: 100;
position: relative;
width: 50px;
height: 30px;
-webkit-border-radius: 10px;
}
.slider>span.slider-container {
min-height: 40px;
display: inline-block;
position: absolute;
top: 0;
left: -8px;
right: 46px;
z-index: 3;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.slider>span.slider-container>span.bar {
background-color: #dadada;
display: inline-block;
position: absolute;
z-index: 1;
left: 0;
right: 0;
height: 11px;
overflow: hidden;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
top: 50%;
transform: translateY(-50%);
}
.slider>span.slider-container>span.bar>span {
background: #00965b;
display: inline-block;
float: left;
height: 11px;
width: 0%;
}
.slider>span.slider-container>span.bar-btn {
display: inline-block;
position: absolute;
min-width: 55px;
max-width: 100px;
height: 32px;
font-weight: bold;
text-align: center;
background: #00965b;
left: 0;
top: 50%;
border-radius: 100px;
border: 2px solid #dadada;
z-index: 5;
color: #fff;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
transform: translateY(-50%);
}
.slider>span.slider-container>span.bar-btn>span {
position: relative;
position: absolute;
tlef: 50%;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<div class="wrap">
<h1 class="heading">Simple Rangeslider</h1>
<input class="slider" value="0" min="3" max="5" step="1" name="001" type="range" />
<input class="slider slider-orange" value="0" min="0" max="25" step="1" name="002" type="range" />
<input class="slider slider-red" value="3556" min="0" max="3556" step="34" name="003" type="range" />
<input class="slider slider-green" value="0" min="0" max="34" step="4" name="004" type="range" />
<input class="slider slider-yellow" value="0" min="0" max="5" step="1" name="005" type="range" />
<input class="slider slider-cyan" value="5" min="0" max="100" step="2" name="006" type="range" />
<input class="slider slider-blue" value="0" min="0" max="5" step="1" name="007" type="range" />
</div>
HI go through this if need any kind of customization in range slider.
Source Codepen

How to apply a CSS blur filter to a background (not image)

I got autocomplete dropdown filled with almost solid background colour
.Suggestions {
text-align: left;
position: absolute;
border: 1px solid #ddd;
border-radius: 5px;
background-color: rgba(235, 235, 235, 0.95);
list-style: none;
margin-top: -9px;
max-height: 143px;
overflow-y: auto;
padding-left: 0;
width: 406px;
}
covering other elements (buttons, inputs ...) when activated
DEACTIVATED
ACTIVATED
and I would like to make an effect similar to safari dropdown when clicked on url where everything behind is almost visible and also blurred.
Is there any way to do that in css? I know that I can create an image and then apply blur filter but the autocomplete is used in many screens with different background so creating image for each screen would be a mammoth task
function myFunction() {
var Textfield = document.getElementById("Textfield");
if (Textfield.value == "")
document.getElementById("back_div").classList.remove("blur");
else
document.getElementById("back_div").classList.add("blur");
}
.blur {
/* Add the blur effect */
filter: blur(2.5px);
-webkit-filter: blur(2.5px);
}
<input id="Textfield" onkeyup="myFunction()" type="text">
<div id="back_div">test text</div>
This question speaks to blur Can you blur the content beneath/behind a div?
There is also opacity going on there as well, here are some ugly things to demonstrate that.
This is somewhat difficult to answer as it does depend on your markup a bit - and CSS pure vs some JavaScript are in some cases very different. here are some things.
.my-select {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
padding: .4em;
background: rgba(235, 235, 235, 0.8);
border: none;
border-radius: 0.5em;
padding: 1em 2em 1em 1em;
font-size: 1em;
}
/* the triagle arrow */
.select-container {
position: relative;
display: inline;
}
/* the triagle arrow */
.select-container:after {
content: "";
width: 0;
height: 0;
position: absolute;
pointer-events: none;
}
/* the triagle arrow */
.select-container:after {
border-left: 5px solid transparent;
border-right: 5px solid transparent;
top: .3em;
right: .75em;
border-top: 8px solid black;
opacity: 0.5;
}
.my-select::-ms-expand {
display: none;
}
.my-select:focus {
outline: none;
border-radius: 0.5em;
}
select.my-select * {
background: rgba(235, 235, 235, 0.8);
opacity: 0.8;
color: lightorange;
}
select.my-select * {
background-color: #bbeeee;
color: #226666;
opacity: 8;
}
select.my-select *:focus {
background: rgba(235, 135, 100, 0.5);
opacity: 0.8;
}
.list-container>.my-list:hover {
opacity: 0.6;
}
.list-container .my-list li:hover {
color: lime;
);
}
.something {
font-size: 2em;
position: relative;
top: -0.7em;
z-index: -2
}
.my-list {
padding-top: 0.4em;
background: rgba(240, 240, 200, 0.9);
border: none;
border-radius: 0.5em;
padding: 1em 1.5em 1em 1em;
font-size: 1.4em;
border: solid 0.25px green;
}
.my-list li {
color: #227777;
list-style-type: square;
}
.other {
color: red;
font-size: 2em;
background-color: lightblue;
position: relative;
top: -2.5em;
left: 1px;
height: 3em;
z-index: -1;
}
.test-backdrop-container {
height: 10em;
border: 1px dotted red;
font-size: 2em;
position: relative;
}
.test-backdrop {
position: relative;
size: 1.5em;
top: 0.75em;
left: 0.75em;
border: solid blue 1px;
background-color: #dddddd;
}
.test-backdrop {
-webkit-backdrop-filter: blur(10px);
opacity: 0.8;
}
<div class="select-container">
<select class="my-select">
<option>one wider text</option>
<option>two</option>
<option>eagle</option>
<option>canary</option>
<option>crow</option>
<option>emu</option>
</select>
</div>
<div class="something">something here</div>
<div class="list-container">
<ul class="my-list">
<li>one wider text</li>
<li>two</li>
<li>eagle</li>
<li>canary</li>
<li>crow</li>
<li>emu</li>
</ul>
</div>
<div class="other">Tester out
<input class="other-input" type="text" value="something in textbox" /> More is not more but not less
</div>
<div class="test-backdrop-container">Test Container
<div class="test-backdrop">Test Backdrop</div>
more text in container more test text
</div>

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.
What should I modify to make the thumb be able to cover the track when scrolling to the most right/left? Thank you.
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>

Resources