主题切换按钮
2024年9月29日小于 1 分钟
主题切换按钮
效果展示
<div class="switch-theme-container">
<label class="switch-theme">
<input type="checkbox" />
<span class="slider"></span>
</label>
</div>
.switch-theme-container {
display: flex;
justify-content: center;
align-items: center;
padding: 12px;
}
.switch-theme {
font-size: 17px;
position: relative;
display: inline-block;
width: 3.5em;
height: 2em;
}
.switch-theme input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #1b1b1f;
transition: 0.5s;
border-radius: 30px;
}
.slider:before {
position: absolute;
content: "";
height: 1.4em;
width: 1.4em;
border-radius: 50%;
left: 10%;
bottom: 15%;
box-shadow: inset 8px -4px 0px 0px #fff000;
background: #1b1b1f;
transition: 0.5s;
}
input:checked + .slider {
background-color: rgb(200, 200, 200);
}
input:checked + .slider:before {
transform: translateX(100%);
box-shadow: inset 15px -4px 0px 15px #fff000;
background: rgb(200, 200, 200);
}