【发布时间】:2020-08-02 02:53:29
【问题描述】:
我注意到,在某些浏览器上选中此复选框时,有时会显示蓝色突出显示。我不完全确定这是从哪里来的,因为我只能在我的 iPhone 上的 Safari 以及 Chrome 开发者工具的设备模式中看到这种行为。但是,桌面版 Chrome 和 Firefox 根本不包含高亮显示。
.center {
top: 50%;
left: 50%;
position: absolute;
transform: translate(-50%, -50%);
}
.switch {
width: 120px;
height: 68px;
position: relative;
display: inline-block;
}
.switch input {
visibility: hidden;
}
.slider {
top: 0;
left: 0;
right: 0;
bottom: 0;
cursor: pointer;
position: absolute;
transition: 0.375s;
border-radius: 68px;
background-color: #414b55;
}
.slider:before {
left: 8px;
bottom: 8px;
width: 52px;
height: 52px;
content: "";
position: absolute;
transition: 0.375s;
border-radius: 50%;
background-color: #ffffff;
}
input:checked + .slider {
background-color: #fa6400;
}
input:checked + .slider:before {
transform: translateX(52px);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example</title>
</head>
<body>
<div class="center">
<label class="switch">
<input type="checkbox">
<span class="slider"></span>
</label>
</div>
</body>
</html>
有人能解释一下它的来源以及如何消除这种影响吗?
【问题讨论】:
-
[type=checkbox] {user-select: none} -
这似乎并没有消除突出显示。
-
我添加了蓝色高光的图像,只是为了让它更清晰。
-
值得一试,它适用于真正的浏览器。
-
[type=checkbox] {outline: 0}您可能需要添加!important