css实现立体checkbox逼真物理按键开关效果代码
代码语言:html
所属分类:布局界面
代码描述:css实现立体checkbox逼真物理按键开关效果代码
代码标签: css 立体 checkbox 逼真 物理 按键 开关
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> * { border: 0; box-sizing: border-box; margin: 0; padding: 0; } :root { --hue: 223; --hue2: 133; --bg: hsl(var(--hue),10%,90%); --fg: hsl(var(--hue),10%,10%); --primary: hsl(var(--hue),90%,50%); --trans-dur: 0.3s; --trans-timing: cubic-bezier(0.83,0,0.17,1); font-size: calc(16px + (24 - 16) * (100vw - 320px) / (2560 - 320)); } body, input { font: 1em/1.5 sans-serif; } body { background-color: var(--bg); color: var(--fg); display: flex; height: 100vh; transition: background-color var(--trans-dur) var(--trans-timing), color var(--trans-dur) var(--trans-timing); } .switch, .switch__input { -webkit-tap-highlight-color: transparent; } .switch { background-color: hsl(var(--hue),10%,90%); border-radius: 0.375em; box-shadow: 0 4.375em 2em hsl(var(--hue),10%,70%) inset, 0 0.125em 0 hsl(var(--hue),10%,90%) inset, 0 0 0.375em hsla(var(--hue),10%,10%,0.5); margin: auto; position: relative; transition: background-color var(--trans-dur) var(--trans-timing), box-shadow var(--trans-dur) var(--trans-timing); width: 3.75em; height: 8.75em; } .switch__input, .switch__lever, .switch__lever-half-top, .switch__lever-half-bottom, .switch__lever-shadow, .switch__lever-shadow:before, .switch__lever-shadow:after { display: block; } .switch__input, .switch__label, .switch__lever-half-top, .switch__lever-half-bottom, .switch__lever-shadow, .switch__lever-shadow:before, .switch__lever-shadow:after { position: absolute; } .switch__input { cursor: pointer; width: 100%; height: 100%; -webkit-appearance: none; appearance: none; } .switch__label { overflow: hidden; width: 1px; height: 1px; } .switch__lever, .switch__lever-shadow { pointer-events: none; } .switch__lever { background-color: hsla(var(--hue),10%,80%); border-radius: 0.25em; box-shadow: 0 0 0.25em hsl(var(--hue),10%,10%) inset, 0.75em 0 0.5em hsl(var(--hue),10%,90%) inset; margin: 0.375em; position: relative; transition: background-color var(--trans-dur) var(--trans-timing), box-shadow var(--trans-dur) var(--trans-timing); width: calc(100% - 0.75em); height: calc(100% - 0.75em); } .switch__lever:before { background-image: linear-gradient(hsla(var(--hue),10%,10%,0),hsla(var(--hue),10%,10%,0.2)); border-radius: inherit; content: ""; display: block; width: 100%; height: 100%; } .switch__lever-half-top, .switch__lever-half-bottom { display: flex; justify-content: center; left: 0.125em; padding: 0.5em; width: calc(100% - 0.25em); height: calc(50% - 0.125em); transition: background-color var(--trans-dur) var(--trans-timing), transform var(--trans-dur) var(--trans-timing); } .switch__lever-half-top { background-color: hsl(var(--hue),10%,85%); border-radius: 0.25em 0.25em 0 0; bottom: 50%; transform-origin: 50% 100%; } .switch__lever-half-top:before, .switch__lever-half-bottom:before { content: ""; display: block; transition: background-color var(--trans-dur) var(--trans-timing), box-shadow var(--trans-dur) var(--trans-timing); } .switch__lever-half-top:before { border-radius: 50%; box-shadow: 0 0 0 0.125em hsl(var(--hue),10%,65%) inset, 0 0.25em 0 hsl(var(--hue),10%,90%) inset, 0 0.125em 0 hsl(var(--hue),10%,90%); width: 1em; height: 1em; } .switch__lever-half-bottom { background-color: hsl(var(--hue),10%,90%); border-radius: 0 0 0.25em 0.25em; align-items: flex-end; top: 50%; transform: rotateX(-35deg); transform-origin: 50% 0; } .switch__lever-half-bottom:before { background-color: hsl(var(--hue2),10%,45%); box-shadow: 0 0.125em 0 hsl(var(--hue2),10%,30%) inset, 0 -0.0625em 0 hsl(var(--hue),10%,90%) inset, 0 0 0.5em hsla(var(--hue2),90%,45%,0); width: 0.25em; height: 1.125em; } .switch__lever-shadow { border-radius: 0.25em; overflow: hidden; top: 0.5em; right: 0; width: 5em; height: calc(100% - 0.25em); } .switch__lever-s.........完整代码请登录后点击上方下载按钮下载查看
网友评论0