【问题标题】:Own image as slider thumb on range. How to style on css自己的图像作为范围上的滑块拇指。如何在 CSS 上设置样式
【发布时间】:2014-02-26 22:42:10
【问题描述】:

如何使用 css 将图像设置为范围输入类型的拇指滑块?它在 Internet Explorer 中不起作用。 Chrome 和 Firefox 没问题,但在 IE 上我的图像被隐藏了还是什么?我使用::-ms-thumb,并尝试将图像设置为背景。如何用 CSS 修复它?

input[type="range"]::-webkit-slider-thumb 
    {
    -webkit-appearance: none;
    background-image: url('../images/slider.png');
    opacity: 1;
    width: 40px;
    height: 19px;
    position: relative;
    top: 0px;
    z-index: 99;
 }
::-moz-range-thumb{
    background-image: url('../images/slider.png');
    width:40px;
    height:19px;
   }
::-ms-thumb{
    background-image: url('../images/slider.png');
    width:40px;
    height:19px;
    z-index: 9999;
    display: block;
    background-color: transparent;
   }

IE, Chrome & Firefox Sliders http://imageshack.com/a/img401/9131/dqwb.jpg

【问题讨论】:

  • 你有没有解决这个问题?我遇到了同样的问题,但没有图像,只是试图将拇指打破滑块轨道的边界。

标签: html image internet-explorer slider range


【解决方案1】:

尝试使用

@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {

    /* IE 10/11 specific style */
    input[type="range"]{
        -webkit-appearance: none !important;
        width:497px;
        height:22px;
        background-image:url('.png');
        background-color:rgba(0,0,0,0);
    }
    .slider::-webkit-slider-thumb{
        -webkit-appearance: none !important;
        height:70px;
        width:70px;
        background-image:url('.png');
    }
    input[type="range"]::-moz-range-track{
        -moz-appearance: none;
        width:497px;
        height:22px;
        background-image:url('.png');
        background-color:rgba(0,0,0,0);
    }
    input[type="range"]::moz-range-thumb {
        -moz-appearance: none;
        height:70px;
        width:70px;
        background-image:none;
    }

    .slider
    {
    width: 226px;
    height: 70px;
    padding: 0px;
    overflow: visible;
    }
    .slider::-ms-thumb
    {
    width: 70px;
    height: 70px;
    padding: 0px;
    border: 0px;
    display:block;
    z-index: 99999;
    background-color: transparent;
    background-image: url('res/img/button.png');
    background-position: center;
    }
    .slider:active::-ms-thumb
    {
    background-image: url('res/img/button.png');
    }
    .slider::-ms-track
    {
    height: 70px;
    margin: 0px;
    border: 0px;
    padding: 0px;
    color: transparent;
    background-color: transparent;
    }
    .slider::-ms-fill-lower, .slider::-ms-fill-upper
    {
    height: 70px;
    margin: 0px;
    border: 0px;
    padding: 0px;
    background-color: transparent;
    background-repeat: no-repeat;
    }
    .slider::-ms-fill-lower
    {
    background-image: url('res/img/slider.png');
    background-position: left top;
    }
    .slider::-ms-fill-upper
    {
    background-image: url('res/img/slider.png');
    background-position: right top;
    }
    input[type="range"].slider::-ms-tooltip
    {
    display: none;
    }
    /* IE 10/11 specific style */  
}

让我知道它是否有效

【讨论】:

  • 对我来说不是开箱即用的。在 IE 11 中会产生一些奇怪的效果,但在 Chrome 和 Mozilla 中完全没有效果
【解决方案2】:

Trident(Internet Explorer 的渲染引擎)不允许 ::ms-thumb 伪元素从 ::ms-track 溢出。要解决这个问题,您需要轨道至少与拇指图像一样高。您仍然可以将轨道样式设置为 apear,就好像它不是全高一样,巧妙地使用了背景。这是一个例子。

input[type="range"] {
  height: 20px; /* must be at least your image's height */
  width: 400px; /* can be anything */
}

input[type="range"]::ms-track {
  height: 20px; /* must be at least your image's height */
  width: 100%;
  /* there are many techniques to make the track seem smaller than it is. */
  /* this technique uses a linear-gradient to make the track seem 4px tall and solid gray. */
  background: linear-gradient(to bottom, transparent 8px, #ccc 8px, #ccc 12px, transparent 12px);
  /* alternatively, if you have an image for the background: */
  background: url('track.png') no-repeat center;
}

input[type="range"]::ms-thumb {
  /* these should be the dimensions of your image */
  height: 20px;
  width: 20px;
  background: #000; /* or your image */
}
<input type="range">

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-12
    • 2021-01-15
    • 1970-01-01
    • 1970-01-01
    • 2021-09-03
    • 2021-06-14
    • 2018-08-12
    • 2018-06-03
    相关资源
    最近更新 更多