我已经使用 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">
它应该是什么样子:
什么是预览:
最佳答案
一个可能的解决方案是设置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/