在Microsoft Edge中切换开关演示文稿

时间:2017-07-10 07:50:50

标签: html css input microsoft-edge

我使用CSS编写了一些切换开关(没有JS)。通过Microsoft Explorer程序预览它们时,它们将作为默认复选框出现。

我已经应用了这些风格:

-webkit-appearance: none;
-moz-appearance: none;
-ms-appearance: none;
-o-appearance: none;
appearance: none;

到CSS文件,但我一直在读,微软边缘没有"播放" WebKit功能。

有什么方法可以解决这个问题吗?



.toggle-switch{
    -webkit-appearance: none;
    -moz-appearance: none;
    -ms-appearance: none;
    -o-appearance: none;
    appearance: none;
    width: 4em;
    height: 2em;
    border-radius: 3em;
    background-color: #DED;
    transform: backgrond-color 0.09s ease-in-out;
    position: relative;
    cursor: pointer;
}
.toggle-switch:checked{
    background: #0D0155;
    cursor: pointer;
}
.toggle-switch::after{
    content: "";
    width: 2em;
    height:2em;
    background-color: white;
    border-radius: 3em;
    position: absolute;
    transform: scale(0.5);
    left: 0;
    transition: left 0.5s ease-in-out;
    cursor: pointer;
    box-shadow: 0 0.1em rgba(0,0,0,0.5);
}
.toggle-switch:checked::after{
    left: 2em;
    cursor: pointer;
}

<input type="checkbox" class="toggle-switch" checked>
<input type="checkbox" class="toggle-switch">
&#13;
&#13;
&#13;

应该是什么样的:

What it should look like

预览为:

What it previews as

1 个答案:

答案 0 :(得分:1)

一种可能的解决方案是设置label样式,而不是为input设置样式并隐藏input。实际上,您可以使用for上的label属性来引用input,这样当您点击它时,它会切换复选框。然后,由于您的input位于display: none,因此出现复选框时不会再出现任何问题。

以下是一个例子:

.checkbox {
  display: none;
}

.toggle-switch {
  width: 4em;
  height: 2em;
  border-radius: 3em;
  background-color: #DED;
  transition: background-color 0.09s ease-in-out;
  position: relative;
  cursor: pointer;
  display: inline-block;
}

.checkbox:checked + .toggle-switch {
  background: #0D0155;
  cursor: pointer;
}

.toggle-switch::after{
  content: "";
  width: 2em;
  height:2em;
  background-color: white;
  border-radius: 3em;
  position: absolute;
  transform: scale(0.5);
  left: 0;
  transition: left 0.5s ease-in-out;
  cursor: pointer;
  box-shadow: 0 0.1em rgba(0,0,0,0.5);
}

.checkbox:checked + .toggle-switch::after{
  left: 2em;
  cursor: pointer;
}
<input type="checkbox" class="checkbox" id="checkbox-id" checked>
<label class="toggle-switch" for="checkbox-id"></label>