我有以下代码来实现切换按钮。问题是,如果我单击切换按钮外部的左上角或左下角(仍在边界矩形内),则会触发单击或检查操作,就像它是一个矩形一样。奇怪的是,这只发生在左侧,而不发生在右侧。
如何阻止这种情况?
(要重现问题,请单击切换开关的左上角或左下角)
.switch {
position: relative;
display: inline-block;
width: 40px;
height: 34px;
}
.switch input {
display: none;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
}
.slider:before {
position: absolute;
content: "";
height: 20px;
width: 20px;
left: 3px;
bottom: 3px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}
input:checked + .slider {
background-color: #2ECC71;
}
input:focus + .slider {
box-shadow: 0 0 1px #2ECC71;
}
input:checked + .slider:before {
-webkit-transform: translateX(25px);
-ms-transform: translateX(25px);
transform: translateX(25px);
}
/* Rounded sliders */
.slider.round {
border-radius: 34px;
height: 25px;
width: 50px;
}
.slider.round:before {
border-radius: 50%;
}
<label class="switch">
<input type="checkbox">
<div id="utm-parameters-control" class="slider round accordion-control"></div>
</label>
最佳答案
您可以使用 class="switch"
从标签中删除宽度和高度。这应该可以解决问题:
.switch {
position: relative;
display: inline-block;
/* width: 40px; */
/* height: 34px; */
关于html - 在具有边框半径的 div 外部单击时单击触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38794081/