【问题标题】:::-ms-thumb appears behind track in MS Edge::-ms-thumb 在 MS Edge 中出现在轨道后面
【发布时间】:2020-01-06 19:00:59
【问题描述】:

我已经创建了一个滑块。

在 chrome 中一切正常。见下图:

但在 MS Edge 中,拇指出现在轨道后面。见下图:

我创建了一个代码笔来解释和展示我的问题:https://codepen.io/glalloue/pen/QGKqNd

已应用 Css(较少):

.form input[type=range] {
    z-index: 1;
    align-self: stretch;
    height: 3px;
    -webkit-appearance: none;
    appearance: none;
    border: none;
    margin: 0;
    &::-webkit-slider-thumb {
        -webkit-appearance: none;
                appearance: none;
        border: none;
        width: 2.5rem;
        height: 2.5rem;
        background-color: white;
        border-radius: 50%;
        box-shadow: inset 0 0 0 1px #cccccc, 0 2px 4px rgba(0, 0, 0, 0.2);
    }
    &::-ms-thumb {
        appearance: none;
        border: none;
        width: 2.5rem;
        height: 2.5rem;
        background-color: pink;
        border-radius: 50%;
        box-shadow: inset 0 0 0 1px #C0C0C0, 0 2px 4px rgba(0, 0, 0, .2);
    }
}

这是一个与 Internet Explorer 类似的问题:::-ms-thumb appears behind track
建议的解决方案是向 ::-ms-track 添加边距,但没有成功。

有什么方法可以让我在 MS edge 中的 ::-ms-thumb 看起来与在 chrome 上的完全一样?

【问题讨论】:

标签: css less range microsoft-edge


【解决方案1】:

在我的情况下,删除 background-image 并定义上下背景不起作用。因此,如果有人仍在寻找它,这就是我的情况。

问题是范围元素的高度。设置为 2px,范围轨道高度 2.5em。

这是一个 Codepen 演示,其中包含一个工作示例 https://codepen.io/piyukore06/pen/abbqJGK?editors=1111

【讨论】:

    【解决方案2】:

    问题是(间接)background-image 输入:

    <input name="perimeter" id="perimeter" style="background-image: -webkit-linear-gradient(left, transparent 0%, rgba(164, 223, 253, 0.8) 1%, rgba(164, 223, 253, 0.8) 25%, black 26%, black 100%);" type="range" min="0" max="4" step="1" value="1">
    

    background-image 是在 Chrome 和 Safari 上设置拇指前后颜色所必需的。

    要解决问题,我需要在 css .form input[type=range] 上设置高度值。
    但如果我这样做,背景图像将采用所有高度值。 它可以在 Chrome 上运行,但不能在 MS edge 上运行。

    因此,要解决它,有必要使用 MS Edge 浏览器特性:

    1. 删除输入中的background-image
    2. 添加 css 样式:-ms-fill-lower-ms-fill-upper 以设置拇指前后的颜色

    结果是:

    <!-- Android & iOS -->
    <input id="perimeter" type="range" min="0" max="4" step="1" style="background-image:-webkit-linear-gradient(left, transparent 0%, rgba(164,223,253,0.8) 1%, rgba(164,223,253,0.8) {{ perimeter *100 / (distances.length -1) | number:0 }}%, black {{ perimeter *100 / (distances.length -1) + 1 | number:0 }}%, black 100%)"/>
    <!-- Windows -->
    <input id="perimeter" type="range" min="0" max="4" step="1" style="height: 2.5rem;"/>
    

    您需要条件输入显示。如果您使用 Angular,请使用 ng-if 仅在 android 和 ios 上显示第一个输入,在 windows 上显示第二个。

    更少的文件是:

    @thumb-color: white;
    @thumb-radius: 50%;
    @thumb-height: 2.5rem;
    @thumb-width: 2.5rem;
    
    @track-width: 100%;
    @track-height: 3px;
    @track-fill-lower-color: rgba(164,223,253,0.8);
    @track-fill-upper-color: black;
    
    .track() {
        -webkit-appearance: none;
        width: @track-width;
        height: @track-height;
        cursor: pointer;
    }
    
    .thumb() {
        -webkit-appearance: none;
        border: none;
        height: @thumb-height;
        width: @thumb-width;
        border-radius: @thumb-radius;
        background: @thumb-color;
        cursor: pointer;
        box-shadow: inset 0 0 0 1px grey, 0 2px 4px rgba(0, 0, 0, .2);
    }
    
    input[type=range] {
      -webkit-appearance: none;
      margin: @thumb-height/2 0;
      width: @track-width;
    
      &::-webkit-slider-runnable-track {
        .track();
        border: none;
      }
    
      &::-webkit-slider-thumb {
        .thumb();
        -webkit-appearance: none;
        margin-top: -1.25rem; // @thumb-height / 2
      }
    
      &::-moz-range-track {
         .track();
         border: none;
      }
      &::-moz-range-thumb {
         .thumb();
      }
    
      &::-ms-track {
        .track();
        background: transparent;
        color: transparent;
      }
      &::-ms-thumb {
        .thumb();
      }
      &::-ms-fill-lower {
        background: @track-fill-lower-color;
      }
      &::-ms-fill-upper {
        background: @track-fill-upper-color;
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2015-07-12
      • 1970-01-01
      • 2016-06-27
      • 1970-01-01
      • 2017-11-13
      • 1970-01-01
      • 1970-01-01
      • 2021-01-19
      • 2020-04-09
      相关资源
      最近更新 更多