html - Microsoft Edge 中的切换显示

标签 html css input microsoft-edge

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

我应用了这些样式:

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

到 CSS 文件,但是我一直在阅读 Microsoft Edge 不“玩” 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">

它应该是什么样子:

What it should look like

什么是预览:

What it previews as

最佳答案

一个可能的解决方案是设置label 的样式而不是设置input 的样式并隐藏input。实际上,您可以使用 label 上的 for 属性来引用 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>

关于html - Microsoft Edge 中的切换显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45006497/

相关文章:

jquery - 切换时更改 Font Awesome 图标

html - 折叠时 Bootstrap 3 导航栏链接在品牌下

javascript - 将 Angular $asyncValidators 与缓存一起使用

javascript - 导航项 100% 分布在一个 div 中,填充均匀

html - 输入类型搜索 - 如何获得白色的占位符和清除按钮?

python - 如何在Python中逐字输入一行?

javascript - 通过选择列表更改的按钮 href 将无法解析(javascript :window. open(window.variable))

javascript - 如何在元素(div、图像)相互接触时触发事件?

python - 如何在 Beautiful Soup 4 (Python) 中使用搜索栏

html - 如何设置表格td的底线