我有这个切换开关,我想将其引入我的网站。
https://jsfiddle.net/njxfnfoa/
<div class="switch-container">
<label class="switch">
<input type="checkbox">
<div class="slider round"></div>
</label>
</div>
CSS 很长,所以我将其保留在 JSFiddle 中。
但是正如您所见,它看起来参差不齐。我正在处理的 PDF 设计看起来像这样。
我怎样才能更好地复制这个平滑的边界?
最佳答案
使用 border: 1px solid rgba(211,211,211, .8);
这样您就可以控制边框不透明度(此处为0.8
)
.switch-container{
position:relative;
}
.switch {
position: relative;
display: inline-block;
width: 65px;
height: 34px;
}
/* Hide default HTML checkbox */
.switch input {
display: none;
}
/* The slider */
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
border: 1px solid rgba(211,211,211, .8);
}
.slider:before {
position: absolute;
content: "";
height: 32px;
width: 32px;
left: 0px;
background-color: #73c82b;
-webkit-transition: .4s;
transition: .4s;
}
input:checked + .slider {
background-color: white;
}
input:focus + .slider {
box-shadow: 0 0 1px white;
}
input:checked + .slider:before {
-webkit-transform: translateX(31px);
-ms-transform: translateX(31px);
transform: translateX(31px);
}
/* Rounded sliders */
.slider.round {
border-radius: 34px;
}
.slider.round:before {
border-radius: 50%;
}
<div class="switch-container">
<label class="switch">
<input type="checkbox">
<div class="slider round"></div>
</label>
</div>
关于html - 当我将 CSS 边框应用于切换开关时,如何修复出现的锯齿状边框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44461769/