';
bottom: 1em;
color: rgba(0, 0, 0, 0.5);
text-shadow: 0 0.1em 0 rgba(255, 255, 255, 0.8);
}
.toggle ~ .switch::after {
content: 'O';
top: 0.6em;
color: rgba(0, 0, 0, 0.45);
text-shadow: 0 0.1em 0 rgba(255, 255, 255, 0.4);
}
把 input 控件设置为 checked状态,以便设置处于 on 状态的样式:
<input type="checkbox" checked="checked" class="toggle">设置处于 on 状态的开关样式:
.toggle:checked ~ .switch {
background: linear-gradient(#a1a2a3, #f0f0f0);
box-shadow:
inset 0 0.2em 0.4em rgba(212, 205, 199, 0.75),
inset 0 0.8em 0 0.1em rgba(255, 255, 255, 0.77),
0 0 0 0.1em rgba(116, 116, 118, 0.8),
0 -0.2em 0.2em rgba(41, 41, 41, 0.18),
0 0 0 0.4em #d4d7d8;
}设置处于 on 状态的文本样式:
.toggle:checked ~ .switch::before {
bottom: 0.3em;
text-shadow: 0 0.1em 0 rgba(255, 255, 255, 0.5);
}
.toggle:checked ~ .switch::after {
top: 1.2em;
text-shadow: 0 0.1em 0 rgba(255, 255, 255, 0.15);
}接下来设置灯光效果。
先设置处于 off 状态的黑暗效果:
.toggle ~ .light {
width: 100vw;
height: 100vh;
background-color: #0a0a16;
z-index: 1;
filter: opacity(0.7);
}再设置处于 on 状态的明亮效果:
.toggle:checked ~ .light {
filter: opacity(0);
}大功告成!
以上就是如何使用纯CSS实现电源开关控件(附源码)的详细内容,更多请关注php中文网其它相关文章!
网站建设是一个广义的术语,涵盖了许多不同的技能和学科中所使用的生产和维护的网站。
关键词:如何运用纯CSS完成电源开关控件(附源码)