css+svg实现三角切换选择三选一效果代码
代码语言:html
所属分类:布局界面
代码描述:css+svg实现三角切换选择三选一效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> .threeway-toggle { --dot-size: 30px; --dot-border-width: 5px; --dot-option-1-color: orange; --dot-option-1-label: "orange"; --dot-option-2-color: rgb(163, 230, 53); --dot-option-2-label: "green"; --dot-option-3-color: rgb(14, 165, 233); --dot-option-3-label: "blue"; position: relative; display: block; width: 100px; height: 100px; transition: scale 300ms ease-in-out; } .threeway-toggle:has(input:focus-visible) { scale: 1.25; } /* tooltip */ .threeway-toggle::before { content: var(--dot-label); position: absolute; top: 50%; left: 50%; translate: -50% -25%; opacity: 0; font-size: 0.7rem; color: var(--dot-label-clr); transition: opacity 300ms ease-in-out; pointer-events: none; } .threeway-toggle:has(input:focus)::before, .threeway-toggle:hover::before { opacity: 1; transition-delay: 300ms, 0ms; } /* triangle */ .threeway-toggle > svg { width: 100%; margin: 0; } .threeway-toggle > svg > path { color: var(--dot-clr); transition: all 300ms ease-in-out; fill: transparent; } /* dot */ .threeway-toggle::after { content: ""; position: absolute; margin: auto; left: var(--dot-left, 0); top: var(--dot-top, 0); translate: -50% -50%; width: var(--dot-size); height: var(--dot-size); aspect-ratio: 1; border-radius: 50%; background-color: var(--clr-bg); border: var(--dot-border-width) solid var(--dot-clr); transition: all 300ms cubic-bezier(0.68, -0.55, 0.27, 1.55); } /* position invisible radio buttons on corners */ .threeway-toggle > input[type="radio"] { position: absolute; opacity: 0; margin: 0; padding: 0; border: none; outline: none; scale: 4; cursor: pointer; z-index: 3; } .threeway-toggle > input#toggle-1 { left: 50%; top: 1.5rem; translate: -50% 0; } .threeway-toggle > input#toggle-2 { right: 1rem; bottom: 1rem; } .threeway-toggle > input#toggle-3 { left: 1rem; bottom: 1rem; } /* option 1 - top */ .threeway-toggle:has(input#toggle-1:checked) { --dot-left: 50%; --dot-top: 1.5rem; --dot-clr: var(--dot-option-1-color); } /* option 2 - bottom right */ .threeway-toggle:has(input#toggle-2:checked) { --dot-left: calc(100% - 20px); --dot-top: calc(100% - 25px); --dot-clr: var(--dot-option-2-color); } /* option 3 - bottom left */ .threeway-toggle:has(input#toggle-3:checked) { --dot-left: 20px; --dot-top: calc(100% - 25px); --dot-clr: var(--dot-option-3-color); } .threeway-toggle:has(input#toggle-1:focus-visible), .threeway-toggle:has(input#toggle-1:hover) { --dot-label: var(--dot-option-1-label); } .threeway-toggle:has(input#toggle-2:focus-visible), .threeway-toggle:has(input#toggle-2:hover) { --dot-label: var(--dot-option-2-label); } .threeway-toggle:has(input#toggle-3:focus-visible), .threeway-toggle:has(input#toggle-3:hover) { --dot-label: var(--dot-option-3-label); } /* general styling */ *, ::before, ::after { box-sizing: border-box; } :root { --clr-bg: #222; --clr-txt: white; --clr-primary: #f5f5f5; --clr-secondary: #075985; } html { background-color: var(--clr-bg); font-family: system-ui; } body { min-height: 100svh; display: flex; flex-direction: column; .........完整代码请登录后点击上方下载按钮下载查看
网友评论0