gpt4 book ai didi

html - Safari 和 IE/Edge 中的复选框 ON/OFF 开关

转载 作者:行者123 更新时间:2023-12-02 09:12:34 25 4
gpt4 key购买 nike

在 Chrome、firefox、opera、brave 中都可以,在 Safari 中 - 过渡效果不好。在 Edge、Internet Esplorer 中 - 外观不起作用,看起来像复选框如何在Edge/IE浏览器中重现safari的过渡和外观?

.mytoggle {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
width: 80px;
height: 30px;
display: inline-block;
position: relative;
border-radius: 15px;
overflow: hidden;
outline: none;
border: none;
cursor: pointer;
background-color: #bdc3c7;
-webkit-transition: .25s ease-in-out;
-moz-transition: .25s ease-out;
-o-transition: .25s ease-out;
transition: .25s ease-out;
}

.mytoggle:before {
width: 22px;
height: 22px;
left: 4px;
top: 4px;
border-radius: 11px;
z-index: 2;
content: "ON OFF";
display: block;
position: absolute;
background: #7f8c9a;
font-size: 14.99px;
font-weight: 700;
text-transform: uppercase;
text-indent: -32px;
word-spacing: 40px;
color: #fff;
white-space: nowrap;
-webkit-transition: .25s ease-out;
-moz-transition: .25s ease-out;
-o-transition: .25s ease-out;
transition: .25s ease-out;
}

.mytoggle:checked {
background-color: #2A3542;
}

input.mytoggle:focus {
outline: 0;
}

.mytoggle:checked:before {
background-color: #41cac0;
color: #41cac0;
left: 54px;
}
<input type="checkbox" checked="checked" class="mytoggle" style="" />

最佳答案

直接设置复选框的样式很麻烦,您可以使用复选框+标签 hack,其中将标签链接到复选框,并将样式应用于标签而不是复选框本身:

.mytoggle {
visibility: hidden;
opacity: 0;
position: absolute;
top: -99999px;
}

.mytoggle + label {
font-family: arial;
vertical-align: middle;
width: 80px;
height: 30px;
display: inline-block;
position: relative;
border-radius: 15px;
overflow: hidden;
outline: none;
border: none;
cursor: pointer;
background-color: #bdc3c7;
-webkit-transition: .25s ease-in-out;
-moz-transition: .25s ease-out;
-o-transition: .25s ease-out;
transition: .25s ease-out;
}

.mytoggle + label:before {
width: 22px;
height: 22px;
left: 4px;
top: 4px;
border-radius: 11px;
z-index: 2;
content: "ON OFF";
display: block;
position: absolute;
background: #7f8c9a;
font-size: 14.99px;
font-weight: 700;
text-transform: uppercase;
text-indent: -32px;
word-spacing: 40px;
color: #fff;
white-space: nowrap;
-webkit-transition: .25s ease-out;
-moz-transition: .25s ease-out;
-o-transition: .25s ease-out;
transition: .25s ease-out;
}

.mytoggle:checked + label {
background-color: #2A3542;
}

input.mytoggle:focus + label {
outline: 0;
}

.mytoggle:checked + label:before {
background-color: #41cac0;
color: #41cac0;
left: 54px;
}
<input type="checkbox" checked="checked" class="mytoggle" id="mycheckbox" />
<label for="mycheckbox" />

关于html - Safari 和 IE/Edge 中的复选框 ON/OFF 开关,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50460280/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com