div+css实现昼夜切换按钮开关效果代码
代码语言:html
所属分类:其他
代码描述:div+css实现昼夜切换按钮开关效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover"> <style> * { border: 0; box-sizing: border-box; margin: 0; padding: 0; } :root { --hue: 223; --trans-dur: 0.4s; --trans-timing: cubic-bezier(0.65,0,0.35,1); font-size: calc(40px + (80 - 40) * (100vw - 320px) / (2560 - 320)); } body, input { color: hsl(var(--hue),10%,10%); font: 1em/1.5 sans-serif; } body { background-color: hsl(var(--hue),10%,90%); display: flex; height: 100vh; transition: background-color var(--trans-dur), color var(--trans-dur); } .switch, .switch__input { position: relative; -webkit-tap-highlight-color: transparent; } .switch { margin: auto; } .switch__input, .switch__input:before { background-color: hsl(var(--hue),10%,10%); } .switch__input { border-radius: 0.75em; cursor: pointer; display: block; width: 3em; height: 1.5em; transition: background-color var(--trans-dur) var(--trans-timing); -webkit-appearance: none; appearance: none; } .switch__input:before { border-radius: 50%; content: ""; display: block; position: absolute; top: 0.125em; left: 0.125em; width: 1.25em; height: 1.25em; transition: background-color var(--trans-dur) var(--trans-timing), transform var(--trans-dur) var(--trans-timing); } .switch__icon, .switch__icon-part { display: block; position: absolute; top: 0; left: 0; } .switch__icon { background-color: hsl(var(--hue),10%,90%); border-radius: 50%; overflow: hidden; pointer-events: none; top: 0.125em; left: 0.125em; width: 1.25em; height: 1.25em; transition: transform var(--trans-dur) var(--trans-timing); } .switch__icon-part { transition: box-shadow var(--trans-dur) var(--trans-timing), transform var(--trans-dur) var(--trans-timing); } .switch__icon-part--1, .switch__icon-part--2, .switch__icon-part--3 { border-radius: 50%; } .switch__icon-part--1 { background-color: hsl(var(--hue),10%,90%); top: calc(50% - 0.375em); left: calc(50% - 0.375em); width: 0.75em; height: 0.75em.........完整代码请登录后点击上方下载按钮下载查看
网友评论0