input[type=”range”] 的浏览器兼容 css 语法

input[type=range]

track 轨道

thumb 滑块

webkit

input[type=range]{
    -webkit-appearance: none;
}

input[type=range]::-webkit-slider-runnable-track {
    width: 300px;
    height: 5px;
    background: #ddd;
    border: none;
    border-radius: 3px;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    border: none;
    height: 16px;
    width: 16px;
    border-radius: 50%;
    background: goldenrod;
    margin-top: -4px;
}

input[type=range]:focus {
    outline: none;
}

input[type=range]:focus::-webkit-slider-runnable-track {
    background: #ccc;
}

firefox

input[type=range]{
    /* 修正 ff 的 focus bug  */
    border: 1px solid white; 

    /*需要适当的宽度设置*/
    width: 300px;
}

input[type=range]::-moz-range-track {
    width: 300px;
    height: 5px;
    background: #ddd;
    border: none;
    border-radius: 3px;
}

input[type=range]::-moz-range-thumb {
    border: none;
    height: 16px;
    width: 16px;
    border-radius: 50%;
    background: goldenrod;
}

/*隐藏 border下的 outline*/
input[type=range]:-moz-focusring{
    outline: 1px solid white;
    outline-offset: -1px;
}

input[type=range]:focus::-moz-range-track {
    background: #ccc;
}

IE10+

input[type=range]::-ms-track {
    width: 300px;
    height: 5px;
    
    /*移除track的背景色,使用ms-fill-lower 和 ms-fill-upper 替代 */
    background: transparent;
    
    /*留出空间使滑块可以溢出透明的 border */
    border-color: transparent;
    border-width: 6px 0;

    /*移除默认标记*/
    color: transparent;
}
input[type=range]::-ms-fill-lower {
    background: #777;
    border-radius: 10px;
}
input[type=range]::-ms-fill-upper {
    background: #ddd;
    border-radius: 10px;
}
input[type=range]::-ms-thumb {
    border: none;
    height: 16px;
    width: 16px;
    border-radius: 50%;
    background: goldenrod;
}
input[type=range]:focus::-ms-fill-lower {
    background: #888;
}
input[type=range]:focus::-ms-fill-upper {
    background: #ccc;
}

参考资料:

How to Style Input Type Range in Chrome, Firefox, and IE