How to customize the HTML5 input range type looks using CSS?

后端 未结 10 2295
粉色の甜心
粉色の甜心 2020-11-27 15:24

I want to customize the looks of the range input type in HTML5 to look something like a progress bar. I\'ve tried applying some common CSS attributes using CSS class but it

10条回答
  •  甜味超标
    2020-11-27 15:52

    See http://afarkas.github.io/webshim/demos/demos/webforms/styler/index.html?range

    It's a tool that produces cross-browser code to style both native and webshims range inputs like you want.

    .ws-range, input[type="range"] {
        /* Range styles: width, height, border-radius, background */
        -webkit-appearance: none;cursor: pointer;border: 0;outline: none;padding: 0;margin: 20.5px 0;
    }
    .ws-range .ws-range-thumb {
        /* Thumb styles: width, height, border, border-radius, background */
    }
    .ws-range.ws-focus .ws-range-thumb {
        /* Thumb focus styles: border-color, background */
    }
    .ws-range.ws-active .ws-range-thumb {
        /* Thumb active styles: border-color, background */
    }
    .ws-range .ws-range-min {
        /* Thumb progress styles: display, background */
        border-radius: /* same as range */;
        height: 100%;
    }
    input[type="range"]::-moz-range-track {
        border: none;background: transparent;
    }
    input[type="range"]::-ms-tooltip {
        display: none;
    }
    input[type="range"]::-webkit-slider-thumb {
        /* Thumb styles: width, height, border, border-radius, background */
        -webkit-appearance: none;
    }
    input[type="range"]::-ms-track {
        /* Range styles: width, height, border-radius, background */
        color: transparent;border: 0;
    }
    input[type="range"]::-moz-range-thumb {
        /* Thumb styles: width, height, border, border-radius, background */
    }
    input[type="range"]::-ms-thumb {
        /* Thumb styles: width, height, border, border-radius, background */
    }
    input[type="range"]:focus::-webkit-slider-thumb {
        /* Thumb focus styles: border-color, background */
    }
    input[type="range"]:focus::-moz-range-thumb {
        /* Thumb focus styles: border-color, background */
    }
    input[type="range"]:focus::-ms-thumb {
        /* Thumb focus styles: border-color, background */
    }
    input[type="range"]:active::-webkit-slider-thumb {
        /* Thumb active styles: border-color, background */
    }
    input[type="range"]:active::-moz-range-thumb {
        /* Thumb active styles: border-color, background */
    }
    input[type="range"]:active::-ms-thumb {
        /* Thumb active styles: border-color, background */
    }
    input[type="range"]::-moz-range-progress {
        /* Thumb progress styles: display, background */
        border-radius: /* same as range */;
        height: 100%;
    }
    input[type="range"]::-ms-fill-lower {
        /* Thumb progress styles: display, background */
        border-radius: /* same as range */;
        height: 100%;
    }
    .no-cssrangeinput input[type="range"] {
        background: transparent;margin: 0;border: 0;min-height: 51px;
    }
    

提交回复
热议问题