Skip to content

Instantly share code, notes, and snippets.

@ChrisLTD
Last active March 20, 2017 17:32
Show Gist options
  • Save ChrisLTD/f12f06ead41d8d3dc33c7cb3c46a8512 to your computer and use it in GitHub Desktop.
Save ChrisLTD/f12f06ead41d8d3dc33c7cb3c46a8512 to your computer and use it in GitHub Desktop.
Cross Browser input[type="range"] styling
// Styling Cross-Browser Compatible Range Inputs with Sass
// Modified from Github: https://github.com/darlanrod/input-range-sass
$track-color: #9896AB !default;
$thumb-color: $color-purple-6 !default;
$thumb-radius: 50% !default;
$thumb-height: 24px !default;
$thumb-width: 24px !default;
$thumb-shadow-size: 4px !default;
$thumb-shadow-blur: 4px !default;
$thumb-shadow-color: rgba(0, 0, 0, .2) !default;
$thumb-border-width: 6px !default;
$thumb-border-color: $color-purple !default;
$thumb-active-color: white !default;
$track-width: 100% !default;
$track-height: 6px !default;
$track-shadow-size: 1px !default;
$track-shadow-blur: 1px !default;
$track-shadow-color: rgba(0, 0, 0, .2) !default;
$track-border-width: 0 !default;
$track-border-color: #cfd8dc !default;
$track-radius: 5px !default;
$contrast: 5% !default;
@mixin shadow($shadow-size, $shadow-blur, $shadow-color) {
// uncomment line below to re-enable shadows
// box-shadow: $shadow-size $shadow-size $shadow-blur $shadow-color, 0 0 $shadow-size lighten($shadow-color, 5%);
}
@mixin track {
transition: background .1s linear;
cursor: pointer;
height: $track-height;
transition: all .2s ease;
width: $track-width;
}
@mixin thumb {
@include shadow($thumb-shadow-size, $thumb-shadow-blur, $thumb-shadow-color);
@include box-sizing(border-box);
transition: background .1s linear;
background: $thumb-color;
border: $thumb-border-width solid $thumb-border-color;
border-radius: $thumb-radius;
cursor: pointer;
height: $thumb-height;
width: $thumb-width;
&:active {
background: $thumb-active-color;
}
}
%range-slider {
-webkit-appearance: none;
margin: $thumb-height / 2 0;
padding: 0;
width: $track-width;
&:focus {
outline: 0;
&::-webkit-slider-runnable-track {
background: lighten($track-color, $contrast);
}
&::-ms-fill-lower {
background: $track-color;
}
&::-ms-fill-upper {
background: lighten($track-color, $contrast);
}
}
&::-webkit-slider-runnable-track {
@include track;
@include shadow($track-shadow-size, $track-shadow-blur, $track-shadow-color);
background: $track-color;
border: $track-border-width solid $track-border-color;
border-radius: $track-radius;
}
&::-webkit-slider-thumb {
@include thumb;
-webkit-appearance: none;
margin-top: ((-$track-border-width * 2 + $track-height) / 2) - ($thumb-height / 2);
}
&::-moz-range-track {
@include track;
@include shadow($track-shadow-size, $track-shadow-blur, $track-shadow-color);
background: $track-color;
border: $track-border-width solid $track-border-color;
border-radius: $track-radius;
}
&::-moz-range-thumb {
@include thumb;
}
&::-ms-track {
@include track;
background: transparent;
border-color: transparent;
border-width: ($thumb-height / 2) 0;
color: transparent;
}
&::-ms-fill-lower {
@include shadow($track-shadow-size, $track-shadow-blur, $track-shadow-color);
background: darken($track-color, $contrast);
border: $track-border-width solid $track-border-color;
border-radius: $track-radius * 2;
}
&::-ms-fill-upper {
@include shadow($track-shadow-size, $track-shadow-blur, $track-shadow-color);
background: $track-color;
border: $track-border-width solid $track-border-color;
border-radius: $track-radius * 2;
}
&::-ms-thumb {
@include thumb;
margin-top: 0;
}
/* hide tooltip in IE */
&::-ms-tooltip {
display: none;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment