css实现checkbox胶囊软开关点击切换效果代码
代码语言:html
所属分类:表单美化
代码描述:css实现checkbox胶囊软开关点击切换效果代码
代码标签: css 胶囊 软开关 点击 切换 checkbox
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> body { display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 1em; min-height: 100vh; font-size: 2em; } .toggle-container { position: relative; border-radius: 3.125em; width: 3.25em; height: 1.875em; } .toggle-checkbox { -webkit-appearance: none; appearance: none; position: absolute; z-index: 1; border-radius: inherit; width: 100%; height: 100%; opacity: 0; cursor: pointer; } .toggle-track { display: flex; align-items: center; position: relative; border-radius: inherit; padding: 0.25em; width: 100%; height: 100%; background-color: #aeaeae; box-shadow: inset 0 0.0625em 0.125em rgba(0, 0, 0, 0.2); transition: background-color 0.4s linear; } .toggle-container.green > .toggle-checkbox:checked + .toggle-track { background-color: #4ccf59; } .toggle-container.blue > .toggle-checkbox:checked + .toggle-track { background-color: #3384fb; } .toggle-container.boo > .toggle-checkbox:checked + .toggle-track { background-color: #ff3372; } .toggle-thumb { position: relative; border-radius: 0.6875em; transform-origin: left; width: 1.375em; height: 1.375em; background-color: #fff; box-shadow: 0 0.25em 0.25em rgba(0, 0, 0, 0.2), inset 0 -0.125em 0.25em rgba(0, 0, 0, 0.2); } .toggle-checkbox.toggled-once + .toggle-track > .toggle-thumb { animation-name: grow-out, bounce-out; animation-duration: 0.2s; animation-timing-function: cubic-bezier(0.75, 0, 1, 1), cubic-bezier(0, 0, 0.3, 1.5); animation-delay: 0s, 0.2s; animation-fill-mode: forwards; } .toggle-checkbox.toggled-once:checked + .toggle-track > .toggle-thumb { animation-name: grow-in, bounce-in; } .toggle-container.boo .toggle-thumb::after { content: ""; position: absolute; top: 0; left: 0; border-radius: inherit; width: 100%; height: 100%; background-image: url("//repo.bfw.wiki/bfwrepo/icon/5de0947920357.png"); background-size: 63.6363636364% 54.5454545455%; background-position: center; background-repeat: no-repeat; box-shadow: inset 0 -0.125em 0.25em rgba(0, 0, 0, 0.2); image-rendering: pixelated; opacity: 0; transition: opacity 0.2s linear; } .toggle-container.boo > .toggle-checkb.........完整代码请登录后点击上方下载按钮下载查看
网友评论0