给大家分享一个用CSS 3.0实现的会发光的复选框特效,效果如下:
以下是代码实现,欢迎大家复制粘贴和收藏。
代码语言:javascript复制<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS 3.0实现会发光复选框</title>
<style>
* {
margin: 0;
padding: 0;
font-family: '微软雅黑', sans-serif;
}
body {
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
background: #191919;
overflow: hidden;
flex-direction: column;
}
label {
position: relative;
width: 240px;
height: 80px;
cursor: pointer;
margin: 20px 0;
}
label input {
opacity: 0;
}
label .check {
position: absolute;
top: 0;
left: 0;
cursor: pointer;
width: 100%;
height: 100%;
background: #101010;
border-radius: 40px;
box-shadow: 0 0 0 4px #101010;
}
label .check::before {
content: '';
position: absolute;
top: calc(50% - 4px);
left: -30px;
width: 8px;
height: 8px;
border-radius: 50%;
background: #f00;
transition: 0.5s;
box-shadow: 0 0 5px #f00,
0 0 10px #f00,
0 0 20px #f00,
0 0 40px #f00,
0 0 80px #f00;
}
label input:checked~.check::before {
background: #101010;
box-shadow: none;
}
label .check::after {
content: '';
position: absolute;
top: calc(50% - 4px);
right: -30px;
width: 8px;
height: 8px;
border-radius: 50%;
box-shadow: none;
transition: 0.5s;
background: #101010;
}
label input:checked~.check::after {
background: #0f0;
box-shadow: 0 0 5px #0f0,
0 0 10px #0f0,
0 0 20px #0f0,
0 0 40px #0f0,
0 0 80px #0f0;
}
label .btn {
position: absolute;
top: 0;
left: 0;
width: 120px;
height: 80px;
border-radius: 40px;
background: #333;
transition: 0.5s;
box-shadow: inset 0 -20px 15px #292929,
inset 0 20px 15px #292929;
}
label .btn::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 52px;
height: 80px;
background: #252525;
border-top-left-radius: 80px;
border-bottom-left-radius: 80px;
filter: blur(2);
}
label .btn::after {
content: '';
position: absolute;
top: 0;
right: 0;
width: 52px;
height: 80px;
background: #252525;
border-top-right-radius: 80px;
border-bottom-right-radius: 80px;
filter: blur(2);
}
label input:checked~.btn {
left: 50%;
}
</style>
</head>
<body>
<label>
<input type="checkbox" name="">
<span class="check"></span>
<span class="btn"></span>
</label>
<label>
<input type="checkbox" name="" checked>
<span class="check"></span>
<span class="btn"></span>
</label>
</body>
</html>