我使用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;
应该是什么样的:
预览为:
答案 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>