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; --bg: hsl(var(--hue),90%,60%); --fg: hsl(var(--hue),90%,10%); --primary: hsl(var(--hue),90%,50%); --trans-dur: 0.3s; --trans-timing: cubic-bezier(0.65,0,0.35,1); font-size: calc(40px + (80 - 40) * (100vw - 320px) / (2560 - 320)); } body, input { font: 1em/1.5 sans-serif; } body { background-color: var(--bg); color: var(--fg); display: flex; height: 100vh; } .switch, .switch__input { position: relative; -webkit-tap-highlight-color: transparent; } .switch { display: block; filter: grayscale(0.9); margin: auto; transition: filter var(--trans-dur) var(--trans-timing); width: 6em; height: 2.75em; } .switch:has(:checked) { filter: grayscale(0); } .switch__input { cursor: pointer; outline: transparent; width: 100%; height: 100%; -webkit-appearance: none; appearance: none; z-index: 2; } .switch__bg { background: radial-gradient( 7.75em 7.75em at 50% 4.0625em, hsla(var(--hue),90%,90%,0) 29.9%, hsl(var(--hue),90%,90%) 30.1% 31.9%, hsl(0,0%,100%) 32.1% 35.2%, hsl(var(--hue),50%,80%) 35.4% 36%, hsl(var(--hue),90%,70%) 36.2% 41.8%, hsl(var(--hue),90%,65%) 42% 43.6%, hsl(var(--hue),50%,80%) 43.8% 44.4%, hsl(0,0%,100%) 44.6% 46.6%, hsl(var(--hue),90%,90%) 46.8% 49.3%, hsl(var(--hue),90%,98%) 49.5% 49.8%, hsla(var(--hue),90%,98%,0) 49.9% ); clip-path: polygon(0 0,100% 0,100% 50%,75% 100%,25% 100%,0 50%); display: block; position: absolute; inset: 0; z-index: 1; } .switch:before, .switch:after, .switch__input:before { content: ""; display: block; position: absolute; top: 0; left: 0; } .switch:before, .switch:after { background: radial-gradient( 60% 60% at 50% 50%, hsla(var(--hue),50%,80%,0) 34%, hsl(var(--hue),50%,80%) 35% 40.5%, hsl(0,0%,100%).........完整代码请登录后点击上方下载按钮下载查看
网友评论0