I am working on an input type range slider. I found out that the Chrome version of input[type=range]::-moz-range-thumb is input[type=range]::-webkit-slider-thumb .
Now, I want the same for input[type=range]::-moz-range-progress.
I have tried input[type=range]::-webkit-slider-progress , input[type=range]::-webkit-slider-runnable-progress .
Still not working so far. Any alternative?
It is totally possible with CSS only.
This dude has done it: https://codepen.io/ShadowShahriar/pen/zYPPYrQ
HTML:
<main>
<input type="range" class="win10-thumb" />
<input type="range" class="win10-thumb" min="0" max="100" value="25" step="5" />
<input type="range" class="win10-thumb" disabled value="64" />
<input type="range" />
<input type="range" min="0" max="100" value="40" step="5" />
<input type="range" disabled value="80" />
</main>
CSS:
html,
body {
height: 100%;
}
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
display: grid;
place-items: center;
}
main {
display: flex;
flex-direction: column;
gap: 2.2em;
padding: 1em 0;
}
html::before {
content: "";
position: fixed;
left: 0;
top: 0;
width: 100vw;
height: 100vh;
background: radial-gradient(circle at center, #fff, #fafafa);
display: block;
}
/* === range theme and appearance === */
input[type="range"] {
font-size: 1.5rem;
width: 12.5em;
}
input[type="range"] {
color: #ef233c;
--thumb-height: 1.125em;
--track-height: 0.125em;
--track-color: rgba(0, 0, 0, 0.2);
--brightness-hover: 180%;
--brightness-down: 80%;
--clip-edges: 0.125em;
}
input[type="range"].win10-thumb {
color: #2b2d42;
--thumb-height: 1.375em;
--thumb-width: 0.5em;
--clip-edges: 0.0125em;
}
#media (prefers-color-scheme: dark) {
html {
background-color: #000;
}
html::before {
background: radial-gradient(circle at center, #101112, #000);
}
input[type="range"] {
color: #f07167;
--track-color: rgba(255, 255, 255, 0.1);
}
input[type="range"].win10-thumb {
color: #3a86ff;
}
}
/* === range commons === */
input[type="range"] {
position: relative;
background: #fff0;
overflow: hidden;
}
input[type="range"]:active {
cursor: grabbing;
}
input[type="range"]:disabled {
filter: grayscale(1);
opacity: 0.3;
cursor: not-allowed;
}
/* === WebKit specific styles === */
input[type="range"],
input[type="range"]::-webkit-slider-runnable-track,
input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
transition: all ease 100ms;
height: var(--thumb-height);
}
input[type="range"]::-webkit-slider-runnable-track,
input[type="range"]::-webkit-slider-thumb {
position: relative;
}
input[type="range"]::-webkit-slider-thumb {
--thumb-radius: calc((var(--thumb-height) * 0.5) - 1px);
--clip-top: calc((var(--thumb-height) - var(--track-height)) * 0.5 - 0.5px);
--clip-bottom: calc(var(--thumb-height) - var(--clip-top));
--clip-further: calc(100% + 1px);
--box-fill: calc(-100vmax - var(--thumb-width, var(--thumb-height))) 0 0
100vmax currentColor;
width: var(--thumb-width, var(--thumb-height));
background: linear-gradient(currentColor 0 0) scroll no-repeat left center /
50% calc(var(--track-height) + 1px);
background-color: currentColor;
box-shadow: var(--box-fill);
border-radius: var(--thumb-width, var(--thumb-height));
filter: brightness(100%);
clip-path: polygon(
100% -1px,
var(--clip-edges) -1px,
0 var(--clip-top),
-100vmax var(--clip-top),
-100vmax var(--clip-bottom),
0 var(--clip-bottom),
var(--clip-edges) 100%,
var(--clip-further) var(--clip-further)
);
}
input[type="range"]:hover::-webkit-slider-thumb {
filter: brightness(var(--brightness-hover));
cursor: grab;
}
input[type="range"]:active::-webkit-slider-thumb {
filter: brightness(var(--brightness-down));
cursor: grabbing;
}
input[type="range"]::-webkit-slider-runnable-track {
background: linear-gradient(var(--track-color) 0 0) scroll no-repeat center /
100% calc(var(--track-height) + 1px);
}
input[type="range"]:disabled::-webkit-slider-thumb {
cursor: not-allowed;
}
/* === Firefox specific styles === */
input[type="range"],
input[type="range"]::-moz-range-track,
input[type="range"]::-moz-range-thumb {
appearance: none;
transition: all ease 100ms;
height: var(--thumb-height);
}
input[type="range"]::-moz-range-track,
input[type="range"]::-moz-range-thumb,
input[type="range"]::-moz-range-progress {
background: #fff0;
}
input[type="range"]::-moz-range-thumb {
background: currentColor;
border: 0;
width: var(--thumb-width, var(--thumb-height));
border-radius: var(--thumb-width, var(--thumb-height));
cursor: grab;
}
input[type="range"]:active::-moz-range-thumb {
cursor: grabbing;
}
input[type="range"]::-moz-range-track {
width: 100%;
background: var(--track-color);
}
input[type="range"]::-moz-range-progress {
appearance: none;
background: currentColor;
transition-delay: 30ms;
}
input[type="range"]::-moz-range-track,
input[type="range"]::-moz-range-progress {
height: calc(var(--track-height) + 1px);
border-radius: var(--track-height);
}
input[type="range"]::-moz-range-thumb,
input[type="range"]::-moz-range-progress {
filter: brightness(100%);
}
input[type="range"]:hover::-moz-range-thumb,
input[type="range"]:hover::-moz-range-progress {
filter: brightness(var(--brightness-hover));
}
input[type="range"]:active::-moz-range-thumb,
input[type="range"]:active::-moz-range-progress {
filter: brightness(var(--brightness-down));
}
input[type="range"]:disabled::-moz-range-thumb {
cursor: not-allowed;
}
On Internet Explorer you can use ::-ms-fill-lower to do this thing and firefox supports ::-moz-range-progress, but on chrome this is not possible only using css.
However, there is a good example below using JS.
It changes the background of the range element using linear-gradient.
https://codepen.io/duplich/pen/qjYQEZ
I am trying to set an opacity on the body. However, I have run into an issue.
When setting the opacity on the body, only its content will be affected. The background is not affected by the opacity.
$("button").click(function() {
$("body").toggleClass("opacity");
});
* {
box-sizing: border-box;
}
body {
background: linear-gradient(to right, #1BBCB1, #37B9E9);
font-family: 'Arial';
margin: 0;
text-align: center;
opacity: 1;
}
body.opacity {
opacity: .3;
}
button {
background-color: transparent;
border: 2px solid #000;
border-radius: 3px;
margin-top: 15px;
padding: 10px;
cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>The background gradient disapears when I set the opacity smaller then 1</p>
<button>Toggle opacity</button>
When doing the same on a div it works fine.
$("button").click(function() {
$("div").toggleClass("opacity");
});
* {
box-sizing: border-box;
}
body {
font-family: 'Arial';
margin: 0;
text-align: center;
}
div {
background: linear-gradient(to right, #1BBCB1, #37B9E9);
opacity: 1;
}
div.opacity {
opacity: .3;
}
button {
background-color: transparent;
border: 2px solid #000;
border-radius: 3px;
margin-top: 15px;
padding: 10px;
cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<p>The background gradient disapears when I set the opacity smaller than 1</p>
<button>Toggle opacity</button>
</div>
But I can't do this with a div. I have to set it on the body. How can I make the opacity affect the body's background?
P.S. Happy new year!
This is because the background of body is propagated to the html element (since this one doesn't have a background set) thus the html is also having the same background of the body. In your case, the opacity works fine with background also but you simply see the one of the html element.
Add a background to html to see the difference:
$("button").click(function() {
$("body").toggleClass("opacity");
});
* {
box-sizing: border-box;
}
html {
background:red;
}
body {
background: linear-gradient(to right, #1BBCB1, #37B9E9);
font-family: 'Arial';
margin: 0;
text-align: center;
opacity: 1;
}
body.opacity {
opacity: .3;
}
button {
background-color: transparent;
border: 2px solid #000;
border-radius: 3px;
margin-top: 15px;
padding: 10px;
cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>The background gradient disapears when I set the opacity smaller then 1</p>
<button>Toggle opacity</button>
Some usefull links to understand this behavior:
https://www.w3.org/TR/css-backgrounds-3/#special-backgrounds
https://css-tricks.com/just-one-of-those-weird-things-about-css-background-on-body/
https://stackoverflow.com/a/47998865/8620333
What's the meaning of "propagated to the viewport" in the CSS spec?
Use rgba() for your linear gradient colors. That way you can set the transparency of the colors. By default have the alpha transparency value set to 1 (a.k.a. 100% opacity = no transparency). Then change the value to something less than 1 so the background becomes semi-transparent.
Note: This solution will only affect the background and not child elements. Of which, may or may not be the intended result.
$("button").click(function() {
$("body").toggleClass("opacity");
});
* {
box-sizing: border-box;
}
body {
background: linear-gradient(to right, rgba(27, 188, 177, 1), rgba(55, 185, 233, 1));
font-family: 'Arial';
margin: 0;
text-align: center;
opacity: 1;
}
body.opacity {
background: linear-gradient(to right, rgba(27, 188, 177, 0.3), rgba(55, 185, 233, 0.3));
}
button {
background-color: transparent;
border: 2px solid #000;
border-radius: 3px;
margin-top: 15px;
padding: 10px;
cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>The background gradient disapears when I set the opacity smaller than 1</p>
<button>Toggle opacity</button>
As far as I know, the opacity property of the body does not exist. So you can obtain the desired effect with something like this:
https://codepen.io/calexandru/pen/YYQLmW
$( function () {
$("#target").on("click", function() {
$('body').addClass('opacity-container');
});
} );
.opacity-container::after {
/*CSS*/
content: "";
background: url(https://firebasestorage.googleapis.com/v0/b/betaproject-8a669.appspot.com/o/Quote-Generator%2F1.jpg?alt=media&token=4de18117-665f-4166-9111-4401af0cd555);
opacity: 0.5;
top: 0;
left: 0;
bottom: 0;
right: 0;
position: absolute;
z-index: -1;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>Click the button for background with opacity</p>
<button id="target">Click me</button>
Is there a possibility to get the same effect as ::-ms-fill-lower on Firefox? Without using JS?
I've already found a workaround in order to achieve that effect on webkit based browsers (e.g. Google Chrome) which uses the pseudo elements :before and :after. But it won't work on the Firefox elements. It seems like ::-moz-range-thumb::before and ::-moz-range-thumb::after aren't legal operations on Firefox, while Google Chrome supports ::-webkit-slider-thumb::before and ::-webkit-slider-thumb::after
Here's a fiddle of the basic outline for the Firefox version:
input[type="range"].slider-track {
border: none;
margin: 10px 0;
width: 100%;
height: 30px;
padding: 0;
overflow-x: hidden;
overflow-y: visible;
background: transparent;
}
input[type="range"].slider-track::-moz-range-thumb {
box-shadow: none;
border: 2px solid grey;
height: 16px;
width: 16px;
border-radius: 16px;
background: white;
}
input[type="range"].slider-track::-moz-range-track {
width: 100%;
height: 2px;
box-shadow: none;
background: blue;
border-radius: 0px;
border: 0px;
}
<div style="max-width: 380px;">
<input type="range" class="slider-track" id="mySlider1"></input>
</div>
Sorry! I've found the answer 20 minutes after posting this... I was searching for that all day long...
Here's the answer:
Use the ::-moz-range-progress element!
Example (works for the snippet)
input[type="range"].slider-track::-moz-range-progress {
background: red;
}
Here you are in Vanilla JS - using gradients for Chrome range input:
<div class="chrome">
<input id="myinput" type="range" value="50" />
</div>
#myinput {background: linear-gradient(to right, #82CFD0 0%, #82CFD0 50%, #fff 50%, #fff 100%);
border: solid 1px #82CFD0;
border-radius: 8px;
height: 7px;
width: 356px;
outline: none;
transition: background 450ms ease-in;
-webkit-appearance: none;
}
document.getElementById("myinput").oninput = function() {
this.style.background = 'linear-gradient(to right, #82CFD0 0%, #82CFD0 '+this.value +'%, #fff ' + this.value + '%, white 100%)'
};
https://codepen.io/saintwycliffe/pen/VBGYXN
You can try this :
$('input[type="range"]').change(function () {
var val = $(this).val()/100;
$(this).css('background-image',
'-webkit-gradient(linear, left top, right top, '
+ 'color-stop(' + val + ', #94A14E), '
+ 'color-stop(' + val + ', #C5C5C5)'
+ ')'
);
});
input[type="range"]{
-webkit-appearance: none;
-moz-apperance: none;
border-radius: 6px;
height: 6px;
background-image: -webkit-gradient(
linear,
left top,
right top,
color-stop(0.15, #94A14E),
color-stop(0.15, #C5C5C5)
);
}
input[type='range']::-webkit-slider-thumb {
-webkit-appearance: none !important;
background-color: #E9E9E9;
border: 1px solid #CECECE;
height: 15px;
width: 15px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="range" min="0" max="100" step="1" value="15">
use input change instead of change, so in all browsers the color should fill up while the user is dragging, and not when the user stops dragging
$(document).on('input change', '#slider', function() {
// codes
});
I have a transition transform on an element in CSS3, but whenever I run the animation, it seems that one of the elements involved in the animation is always hidden for the duration of the animation.
Here is the CSS, HTML and JavaScript code:
CSS
div.toggle {
font-family: Arial, Helvetica, sans-serif;
width: 92px;
overflow: hidden;
cursor: default;
border-radius: 3px;
border: 1px solid #919191;
float: right;
position: relative;
height: 26px
}
div.toggle div.control-cont {
display: -webkit-box;
position: absolute;
-webkit-transition:all 0.2s ease-in-out;
width: 155px;
}
div.toggle span {
display: inline-block;
float: left;
text-transform: uppercase;
position: relative;
float: left;
}
div.toggle span.on {
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(41,90,178,1)), color-stop(50%,rgba(64,133,236,1)), color-stop(51%,rgba(77,143,239,1)), color-stop(100%,rgba(118,173,252,1)));
background: -webkit-linear-gradient(top, rgba(41,90,178,1) 0%,rgba(64,133,236,1) 50%,rgba(77,143,239,1) 51%,rgba(118,173,252,1) 100%);
font-weight: bold;
color: #fff;
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.5);
font-size: 16px;
width: 57px;
text-align: center;
padding-top: 4px;
}
div.toggle.important span.on {
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(210,102,8,1)), color-stop(2%,rgba(234,115,10,1)), color-stop(4%,rgba(248,123,12,1)), color-stop(50%,rgba(255,140,14,1)), color-stop(51%,rgba(255,153,33,1)), color-stop(100%,rgba(254,188,86,1)));
background: -webkit-linear-gradient(top, rgba(210,102,8,1) 0%,rgba(234,115,10,1) 2%,rgba(248,123,12,1) 4%,rgba(255,140,14,1) 50%,rgba(255,153,33,1) 51%,rgba(254,188,86,1) 100%);
}
div.toggle span.handle {
border-radius: 3px;
height: 26px;
border-left: 1px solid #9f9f9f;
border-right: 1px solid #9f9f9f;
width: 39px;
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(239,239,239,1)), color-stop(3%,rgba(206,206,206,1)), color-stop(100%,rgba(251,251,251,1)));
background: -webkit-linear-gradient(top, rgba(239,239,239,1) 0%,rgba(206,206,206,1) 3%,rgba(251,251,251,1) 100%);
z-index: 10;
left: -5px
}
div.toggle span.off {
font-size: 16px;
font-weight: bold;
color: #7e7e7e;
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(181,181,181,1)), color-stop(2%,rgba(207,207,207,1)), color-stop(4%,rgba(223,223,223,1)), color-stop(6%,rgba(231,231,231,1)), color-stop(50%,rgba(239,239,239,1)), color-stop(51%,rgba(249,249,249,1)), color-stop(100%,rgba(254,254,254,1)), color-stop(100%,rgba(251,251,251,1)));
background: -webkit-linear-gradient(top, rgba(181,181,181,1) 0%,rgba(207,207,207,1) 2%,rgba(223,223,223,1) 4%,rgba(231,231,231,1) 6%,rgba(239,239,239,1) 50%,rgba(249,249,249,1) 51%,rgba(254,254,254,1) 100%,rgba(251,251,251,1) 100%);
left: -10px;
text-align: center;
padding-top: 4px;
width: 57px;
}
div.toggle input {
display: none;
}
JavaScript:
(function($) {
$.fn.toggle = function()
{
this.each(function() {
var toggle_class = ($(this).attr('checked')) ? 'checked' : '';
var important_class = ($(this).hasClass('important')) ? 'important' : '';
var this_transformed = false;
var this_toggle = $('<div class="toggle">\
<div class="control-cont">\
<span class="on">on</span>\
<span class="handle"></span>\
<span class="off">off</span>\
</div>\
</div>');
this_toggle.addClass(toggle_class);
this_toggle.addClass(important_class);
var thecheckbox = this;
$(this).replaceWith(this_toggle);
this_toggle.append(thecheckbox);
if(toggle_class != 'checked')
{
this_toggle.find('.control-cont').css({ left: '-53px' });
}
this_toggle.click(toggle_switch);
$(thecheckbox).change(toggle_switch);
function toggle_switch() {
var self = $(this);
var this_off = $(this).find('.off');
var this_on = $(this).find('.on');
var this_container = $(this).find('.control-cont');
var the_checkbox = $(this).find('input[type="checkbox"]');
if($(this).hasClass('checked'))
{
if(!this_transformed)
{
this_container.css("-webkit-transform", "translate(-53px, 0px)");
this_transformed = true;
}
else
{
this_container.css("-webkit-transform", "translate(53px, 0px)");
}
self.removeClass('checked');
the_checkbox.attr('checked', false);
}
else
{
if(!this_transformed)
{
this_container.css("-webkit-transform", "translate(53px, 0px)");
this_transformed = true;
}
else
{
this_container.css("-webkit-transform", "translate(0px, 0px)");
}
self.addClass('checked');
the_checkbox.attr('checked', true);
}
};
});
};
}) ( jQuery );
Essentially, the animation moves the entire div.control-con along or backwards, depending on the checkbox's status. Everything works fine in Chrome and Safari, but when running in Mobile Safari, for some reason the span.off and span.on elements are not displayed when the animation is run.
Which span element is hidden depends on the direction of the animation. Here's a screenshot of the problem, you'll notice that the span.off isn't displayed until the animation is complete:
I've also put this into a jsFiddle for reference: http://jsfiddle.net/kShEQ/
Mobile Safari is not an exact clone of normal safari and the webkit engine. It's a myth that there's a single webkit engine haha. Mobile Safari renders transitions differently. From what I've seen, the syntax in which you enter the transition values differs slightly. Check out this semi-similar stackoverflow question:
Scaling problem with -webkit-transform with mobile safari on iPad