Range Slider styling doesn't work on edge - css

My CSS style for the range slider doesn't work on Edge. How can I fix the Problem?
I searched on the web for a solution. And added some codes but still not working.
.slider {
-webkit-appearance: none;
width: 100%;
height: 5px;
border-radius: 5px;
background: #d3d3d3;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 15px;
height: 15px;
border-radius: 50%;
background: #33A2D9;
cursor: pointer;
}
.slider::-moz-range-thumb {
width: 15px;
height: 15px;
border-radius: 50%;
background: #33A2D9;
cursor: pointer;
}
/*I added this to fix for edge but it doesn't work */
input[type=range]::-ms-thumb{
width: 15px !important;
height: 15px !important;
border-radius: 50% !important;
background: #33A2D9 !important;
cursor: pointer !important;;
}
input[type=range]::-ms-fill-upper {
border-radius: 5px !important;
background: #d3d3d3 !important;
}
input[type=range]::-ms-fill-lower {
border-radius: 5px !important;
background: #d3d3d3 !important;
}
What it should look like (for example on Firefox):
What it look like on edge:

Your "mistake" (if we can call it that) was giving the input a background. You want to give it background-color of transparent and give the -track the desired shade.
Also, as a minor side note and general rule, avoid using background instead of background-color. It is shorter, but it sets a bunch of other background- properties, which you normally don't care about but are a source of common bugs.
Since it tends to be repetitive, I wrote it in SCSS:
$input-height: 16px;
$track-height: 6px;
$thumb-bg: #33A2D9;
$track-bg: #d3d3d3;
#mixin slider-thumb {
width: $input-height;
height: $input-height;
border-radius: $input-height/2;
background-color: $thumb-bg;
appearance: none;
}
#mixin slider-track {
height: $track-height;
border-radius: $track-height/2;
background-color: $track-bg;
appearance: none;
}
.slider[type=range] {
-webkit-transition: .2s;
-webkit-appearance: none;
appearance: none;
width: 100%;
height: $input-height;
background-color: transparent;
outline: none;
opacity: 0.7;
transition: opacity .2s;
cursor: pointer;
&:hover, &:focus, &:active {
opacity: 1;
}
&::-webkit-slider- {
&runnable-track {
-webkit-appearance: none;
#include slider-track;
}
&thumb {
-webkit-appearance: none;
#include slider-thumb;
margin-top: -($input-height - $track-height)/2;
}
}
&::-moz-range- {
&track {
#include slider-track;
}
&thumb {
#include slider-thumb;
margin-top: 0;
}
}
&::-ms- {
&track {
#include slider-track;
}
&fill-upper {
#include slider-track;
}
&fill-lower {
#include slider-track;
}
&thumb {
#include slider-thumb;
margin-top: 0;
}
}
}
Resulting in the following CSS:
.slider[type=range] {
-webkit-appearance: none;
-webkit-transition: .2s;
width: 100%;
height: 16px;
border-radius: 3px;
background-color: transparent;
outline: none;
opacity: 0.7;
transition: opacity .2s;
cursor: pointer;
}
.slider[type=range]:hover, .slider[type=range]:focus, .slider[type=range]:active {
opacity: 1;
}
.slider[type=range]::-webkit-slider-runnable-track {
height: 6px;
border-radius: 3px;
background-color: #d3d3d3;
}
.slider[type=range]::-webkit-slider-thumb {
width: 16px;
height: 16px;
border-radius: 8px;
background-color: #33A2D9;
-webkit-appearance: none;
appearance: none;
margin-top: -5px;
}
.slider[type=range]::-moz-range-track {
height: 6px;
border-radius: 3px;
background-color: #d3d3d3;
}
.slider[type=range]::-moz-range-thumb {
width: 16px;
height: 16px;
border-radius: 8px;
background-color: #33A2D9;
margin-top: 0;
}
.slider[type=range]::-ms-track {
height: 6px;
border-radius: 3px;
background-color: #d3d3d3;
}
.slider[type=range]::-ms-fill-upper {
height: 6px;
border-radius: 3px;
background-color: #d3d3d3;
}
.slider[type=range]::-ms-fill-lower {
height: 6px;
border-radius: 3px;
background-color: #d3d3d3;
}
.slider[type=range]::-ms-thumb {
width: 16px;
height: 16px;
border-radius: 8px;
background-color: #33A2D9;
margin-top: 0;
}
<input type=range class=slider>
Playground here.

Related

How can I make a transition from left to right?

I wanted my button to change the background color on hover with a transition from left to right. This is what I tried:
.btn {
background-color: transparent;
transition-property: background-color, left, right;
transition-duration: 1s;
color: #007eb6;
border: 1px solid #007eb6;
&:hover {
background-color: #007eb6;
color: #fafafa;
border: 1px solid #007eb6;
}
Here is a codepen you can use (Its not mine)
The trick is to set background-position to 0% and on hover change it to 100%
<button>Bangladesh</button>
CSS Code
button {
background-color: red;
color: #fff;
border: none;
outline: none;
padding: 20px 60px;
font-size: 20px;
text-transform: uppercase;
position: relative;
z-index: 1;
cursor: pointer;
}
button::before {
content: "";
position: absolute;
left: 0;
top: 0;
height: 100%;
width: 0;
background-color: green;
transition: .5s;
z-index: -1;
}
button:hover::before {
width: 100%;
}

can attribute selectors be used with styled-components?

after doing a bit of research, I could not find information regarding the usage of attribute selectors (that is, [attr=value]) in styled-components. however, I still imagine it is highly possible for styled-components to support attribute selectors... but should it not, what are some equivalents of it?
for instance, if I have the code below
.squares li[data-level='1'] {
background-color: var(--light);
}
.squares li[data-level='2'] {
background-color: var(--medium);
}
.squares li[data-level='3'] {
background-color: var(--dark);
}
.squares li[data-level='4'] {
background-color: var(--darkest);
}
how do I achieve it via styled-components?
It is very simple, need create styled component, example "Squares" and define styles for nested list items with attribute "data-value='N'"
const Squares = styled.div`
li[data-level='1'] {
background-color: var(--light);
}
li[data-level='2'] {
background-color: var(--medium);
}
li[data-level='3'] {
background-color: var(--dark);
}
li[data-level='4'] {
background-color: var(--darkest);
}
`
I figured it out; this is what I did:
const SquareListItem = styled.li`
border-radius: 3px;
border: 1px rgba(27, 31, 35, 0.06) solid;
background-color: ${colour[0]};
&[data-level='1'] {
background-color: ${colour[1]};
}
&[data-level='2'] {
background-color: ${colour[2]};
}
&[data-level='3'] {
background-color: ${colour[3]};
}
&[data-level='4'] {
background-color: ${colour[4]};
}
/* tooltip */
&[data-tooltip] {
position: relative;
cursor: pointer;
}
&[data-tooltip]:before,
&[data-tooltip]:after {
visibility: hidden;
opacity: 0;
pointer-events: none;
}
&[data-tooltip]:before {
position: absolute;
z-index: 999;
bottom: 150%;
left: 100%;
margin-bottom: 5px;
margin-left: -90px;
padding: 7px;
width: 150px;
border-radius: 3px;
background-color: #000;
background-color: hsla(0, 0%, 20%, 0.9);
color: #fff;
content: attr(data-tooltip);
text-align: center;
font-size: 10px;
line-height: 1.2;
}
&[data-tooltip]:after {
position: absolute;
bottom: 150%;
left: 50%;
margin-left: -5px;
width: 0;
border-top: 5px solid hsla(0, 0%, 20%, 0.9);
border-right: 5px solid transparent;
border-left: 5px solid transparent;
content: ' ';
font-size: 0;
line-height: 0;
z-index: inherit;
}
/* show tooltip content on hover */
&[data-tooltip]:hover:before,
&[data-tooltip]:hover:after {
visibility: visible;
opacity: 1;
}
`

Firefox browser input problem. How to fix?

The slider in Firefox looked gray by default. As far as I understand, Firefox does not accept many css tags, such as input[type=range]::-webkit-slider-thumb, as an example, I tried adding moz-range-thumb tags to the existing CSS, something like I managed to do it, but still the background of the slider is white, and this is only in Firefox.
How it looks after changes:
And my css code:
input[type=range] {
-webkit-appearance: none;
width: 100%;
}
input[type=range]:focus {
outline: none;
}
input[type=range]:focus::-webkit-slider-runnable-track {
background: linear-gradient(
90deg
,#29bddd,#923ddd),#c4c4c4;
}
input[type=range]:focus::-ms-fill-lower {
background: linear-gradient(
90deg
,#29bddd,#923ddd),#c4c4c4;
}
input[type=range]:focus::-ms-fill-upper {
background: linear-gradient(
90deg
,#29bddd,#923ddd),#c4c4c4;
}
input[type=range]::-webkit-slider-runnable-track {
width: 100%;
height: 5px;
cursor: pointer;
animate: 0.2s;
background: linear-gradient(
90deg
,#29bddd,#923ddd),#c4c4c4;
border-radius: 1px;
box-shadow: none;
border: 0;
}
input[type=range]::-webkit-slider-thumb {
z-index: 2;
position: relative;
box-shadow: 0px 0px 0px #000;
border: 1px solid #2497e3;
height: 18px;
width: 18px;
border-radius: 25px;
background: #a1d0ff;
cursor: pointer;
-webkit-appearance: none;
margin-top: -7px;
}
input[type=range]::-moz-range-thumb {
z-index: 2;
position: relative;
box-shadow: 0px 0px 0px #000;
border: 1px solid #2497e3;
height: 18px;
width: 18px;
border-radius: 25px;
background: #a1d0ff;
cursor: pointer;
-webkit-appearance: none;
margin-top: -7px;
}
input[type=range]::-moz-range-track {
width: 100%;
height: 5px;
cursor: pointer;
animate: 0.2s;
background: linear-gradient(
90deg
,#29bddd,#923ddd),#c4c4c4;
border-radius: 1px;
box-shadow: none;
border: 0;
}
input[type=range]:-moz-focusring {
outline: none;
}
input[type=range]:focus::-moz-range-track {
background: linear-gradient(
90deg
,#29bddd,#923ddd),#c4c4c4;
}
How i can remove this white background in Firefox browser?
In addition to adding background for input[type=range].
you can set height = 0 for input[type=range].
body{
background:gray;
}
input[type=range] {
-webkit-appearance: none;
width: 100%;
height:0;
/* background:none; */
}
input[type=range]:focus {
outline: none;
}
input[type=range]:focus::-webkit-slider-runnable-track {
background: linear-gradient(
90deg
,#29bddd,#923ddd),#c4c4c4;
}
input[type=range]:focus::-ms-fill-lower {
background: linear-gradient(
90deg
,#29bddd,#923ddd),#c4c4c4;
}
input[type=range]:focus::-ms-fill-upper {
background: linear-gradient(
90deg
,#29bddd,#923ddd),#c4c4c4;
}
input[type=range]::-webkit-slider-runnable-track {
width: 100%;
height: 5px;
cursor: pointer;
animate: 0.2s;
background: linear-gradient(
90deg
,#29bddd,#923ddd),#c4c4c4;
border-radius: 1px;
box-shadow: none;
border: 0;
}
input[type=range]::-webkit-slider-thumb {
z-index: 2;
position: relative;
box-shadow: 0px 0px 0px #000;
border: 1px solid #2497e3;
height: 18px;
width: 18px;
border-radius: 25px;
background: #a1d0ff;
cursor: pointer;
-webkit-appearance: none;
margin-top: -7px;
}
input[type=range]::-moz-range-thumb {
z-index: 2;
position: relative;
box-shadow: 0px 0px 0px #000;
border: 1px solid #2497e3;
height: 18px;
width: 18px;
border-radius: 25px;
background: #a1d0ff;
cursor: pointer;
-webkit-appearance: none;
margin-top: -7px;
}
input[type=range]::-moz-range-track {
width: 100%;
height: 5px;
cursor: pointer;
animate: 0.2s;
background: linear-gradient(
90deg
,#29bddd,#923ddd),#c4c4c4;
border-radius: 1px;
box-shadow: none;
border: 0;
}
input[type=range]:-moz-focusring {
outline: none;
}
input[type=range]:focus::-moz-range-track {
background: linear-gradient(
90deg
,#29bddd,#923ddd),#c4c4c4;
}
<input type="range">
You should just set the background for input[type=range].
Here's a simplified example:
input[type=range] {
-webkit-appearance: none;
width: 500px;
height: 20px;
background: pink;
}
/* Firefox */
input[type=range]::-moz-range-thumb {
background: blue;
}
input[type=range]::-moz-range-track {
background: purple;
}
/* Chrome */
input[type=range]::-webkit-slider-thumb {
background: blue;
margin-top: -5px;
}
input[type=range]::-webkit-slider-runnable-track {
background: purple;
height: 5px;
}
<input type="range" />

Styling input type number

I am trying to stylize the input type number. In this way: https://ant.design/components/input-number/ (first input). But without using the ant design framework. Where there are inner-spin, outer-spin I am trying add white background, gray lines and change the inner-spin color, outer-spin. Change the background color I can, but I can not spinns any more. I can not see them.
I can use the bootstrap-react framework, but I do not see such a number input
Code here: https://stackblitz.com/edit/react-cojnud
input[type=number] {
line-height: 27px;
box-sizing: border-box;
font-variant: tabular-nums;
line-height: 1.5;
list-style: none;
-webkit-font-feature-settings: 'tnum';
font-feature-settings: 'tnum';
position: relative;
width: 100%;
height: 32px;
padding: 4px 11px;
color: rgba(0,0,0,0.65);
font-size: 14px;
line-height: 32px;
background-image: none;
-webkit-transition: all .3s;
transition: all .3s;
display: inline-block;
width: 90px;
margin: 0;
padding: 0;
border: 1px solid #d9d9d9;
border-radius: 4px;
}
input[type=number].mod::-webkit-inner-spin-button {
width: 30px;
height: 30px;
position: relative;
display: block;
overflow: hidden;
color: rgba(0,0,0,0.45);
font-weight: bold;
line-height: 0;
text-align: center;
-webkit-transition: all .1s linear;
transition: all .1s linear;
background-color: #fff;
}
input[type=number]::-webkit-inner-spin-button:hover {
color: blue;
}
input[type=number]:hover {
border-color: #40a9ff;
border-right-width: 1px !important;
}
input[type="number"].mod::-webkit-inner-spin-button {
-webkit-appearance: none;
background-color: white;
color: black;
}
Hy there,
try to remove -webkit-appearance: none;
And you will see the spinners again!
You won't be able to modify it across browsers. Better to use it following manner:
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
/* display: none; <- Crashes Chrome on hover */
-webkit-appearance: none;
margin: 0; /* <-- Apparently some margin are still there even though it's hidden */
}
input[type=number] {
-moz-appearance:textfield; /* Firefox */
}
.number-wrapper {
position: relative;
width: 300px;
height: 30px;
}
.number-wrapper input {
width: 100%;
height: 30px;
box-sizing: border-box;
padding-right: 18px;
text-align: right;
}
.number-wrapper .rocker {
position: absolute;
background: #FFF;
border: 1px solid lightblue;
right: 0;
padding: 2px 4px;
color: #ccc;
transition: all ease-in 100ms;
height: 50%;
box-sizing: border-box;
line-height: 12px;
cursor: pointer;
visibility: hidden;
}
.number-wrapper:hover .rocker {
visibility: visible;
transition: all ease-in 300ms;
}
.number-wrapper .rocker.up {
top: 0;
}
.number-wrapper .rocker.down {
bottom: 0;
transform: rotate(180deg);
border-bottom: none;
}
.number-wrapper .rocker:hover,
.number-wrapper .rocker:focus {
box-shadow: 0 0 4px lightblue;
}
.number-wrapper .rocker:active {
transform: scale(0.4);
}
.number-wrapper .rocker.down:active {
transform: rotate(180deg) scale(0.4);
}
<div class="number-wrapper"><span class="rocker up">^</span><span class="rocker down">^</span><input class="mod" type="text" /></div>
Try This
jQuery('<div class="quantity-nav"><div class="quantity-button quantity-up">⮙</div><div class="quantity-button quantity-down">⮛</div></div>').insertAfter('.quantity input');
jQuery('.quantity').each(function() {
var spinner = jQuery(this),
input = spinner.find('input[type="number"]'),
btnUp = spinner.find('.quantity-up'),
btnDown = spinner.find('.quantity-down'),
min = input.attr('min'),
max = input.attr('max');
btnUp.click(function() {
var oldValue = parseFloat(input.val());
if (oldValue >= max) {
var newVal = oldValue;
} else {
var newVal = oldValue + 1;
}
spinner.find("input").val(newVal);
spinner.find("input").trigger("change");
});
btnDown.click(function() {
var oldValue = parseFloat(input.val());
if (oldValue <= min) {
var newVal = oldValue;
} else {
var newVal = oldValue - 1;
}
spinner.find("input").val(newVal);
spinner.find("input").trigger("change");
});
});
.quantity {
position: relative;
}
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button
{
-webkit-appearance: none;
margin: 0;
}
input[type=number]
{
-moz-appearance: textfield;
border-radius: 5%;
}
.quantity input {
width: 45px;
height: 35px;
line-height: 1.65;
float: left;
display: block;
padding: 0;
margin: 0;
padding-left: 20px;
border: 1px solid #eee;
}
.quantity input:focus {
outline: 0;
}
.quantity-nav {
float: left;
position: relative;
height: 40px;
}
.quantity-button {
position: relative;
cursor: pointer;
border-left: 1px solid #eee;
width: 20px;
text-align: center;
color: #333;
font-size: 13px;
font-family: "Trebuchet MS", Helvetica, sans-serif !important;
line-height: 1.7;
-webkit-transform: translateX(-100%);
transform: translateX(-100%);
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
}
.quantity-button.quantity-up {
position: absolute;
height: 46%;
top: 0;
margin-top: 0px;
border-bottom: 1px solid #eee;
}
.quantity-button.quantity-down {
position: absolute;
bottom: 4px;
height: 46%;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="quantity">
<input type="number" min="1" step="1" value="1">
</div>
See Code Link

Target CSS transition at pseudo-element "Arrow"?

I have a DIV with an "arrow" at the bottom, not unlike a speech bubble from a comic book, which appears on the hover state:
The arrow is created with the :after and :before pseudo elements.
I have a transition for the hover for the border color and the box shadow.
My problem is that the "arrow" just "appears". No fade like the other items, but I can't figure out how to target the "arrow". "All" does not look right either.
Ideally, I'd love to have a delay on the arrow and a simple fade or wipe.
Here's the CSS:
.item-selector-button {
position: relative;
text-align: center;
cursor: pointer;
border: 1px solid #cecece;
padding: 15px;
border-radius: 0;
color: #000;
width: 160px;
height: 120px;
transition: all ease-in-out 0.1s, box-shadow ease-in-out 0.1s;
}
.item-selector-button .title {
color: #3e53a4;
font-size: 12px;
margin: 0;
padding-top: -3px;
font-family: "PrecisionSans_W_Md", "Helvetica Neue", Arial, sans-serif;
}
.item-selector-button .divider {
height: 1px;
width: 20px;
background-color: #cecece;
margin: 4px auto 10px;
}
.item-selector-button .image {
background: #fff url("../images/box.png") center center no-repeat;
width: 64px;
height: 57px;
margin: 4px auto;
}
.item-selector-button:hover, .item-selector-button.hover {
padding: 14px;
}
.item-selector-button:hover:after, .item-selector-button.hover:after {
content: "";
position: absolute;
bottom: -12px;
left: 68px;
border-width: 12px 12px 0;
border-style: solid;
border-color: #fff transparent;
transition-delay: 0.3s;
}
.item-selector-button:hover:before, .item-selector-button.hover:before {
content: "";
position: absolute;
bottom: -15px;
left: 65px;
border-width: 15px 15px 0;
border-style: solid;
border-color: #3e53a4 transparent;
transition-delay: 0.3s;
}
.item-selector-button:active, .item-selector-button.active {
border-width: 2px;
border-color: #3e53a4;
background-color: #3e53a4;
}
.item-selector-button:active:before, .item-selector-button.active:before {
content: "";
position: absolute;
bottom: -15px;
left: 65px;
border-width: 15px 15px 0;
border-style: solid;
border-color: #3e53a4 transparent;
transition-delay: 0.3s;
}
.item-selector-button:active .title, .item-selector-button.active .title {
color: #fff;
}
.item-selector-button:active .divider, .item-selector-button.active .divider {
background-color: #fff;
}
.item-selector-button:active .image, .item-selector-button.active .image {
background-color: #3e53a4;
}
.item-selector-button:active:hover, .item-selector-button.active:hover {
padding: 15px;
box-shadow: none;
}
.item-selector-button:active:hover:after, .item-selector-button.active:hover:after {
content: "";
position: absolute;
bottom: -12px;
left: 68px;
border-width: 12px 12px 0;
border-style: solid;
border-color: #3e53a4 transparent;
transition-delay: 0.3s;
}
.item-selector-button.disabled {
pointer-events: none;
cursor: not-allowed;
}
.item-selector-button.disabled .title {
color: #c3c3c3;
}
.item-selector-button.disabled .image {
background-image: url("../images/box-disabled.png");
}
.item-selector-button.disabled:hover {
padding: 15px;
border: 1px solid #cecece;
box-shadow: none;
}
You only have pseudoelements on the hovered element, so there is nothing to transition from/to. You need to add the pseudo elements on the non-hover state element.
Example transitioning visibility:
.item-selector-button:before {
.arrow-inside(...);
transition:all 5s ease;
transition-delay: 0.3s;
visibility:hidden;
}
.item-selector-button:after {
.arrow-outside(...);
transition:all 5s ease;
transition-delay: 0.3s;
visibility:hidden;
}
.item-selector-button:hover:before {
visibility:visible;
}
.item-selector-button:hover:after {
visibility:visible;
}

Resources