svg+css实现自适应黑白主题切换的顶部菜单效果代码
代码语言:html
所属分类:菜单导航
代码描述:svg+css实现自适应黑白主题切换的顶部菜单效果代码
代码标签: svg css 自适应 黑白 主题 切换 顶部 菜单
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" class="dark"> <head> <meta charset="UTF-8"> <link type="text/css" rel="stylesheet" href="//repo.bfw.wiki/bfwrepo/css/normalize.5.0.css"> <style> *, *:after, *:before { box-sizing: border-box; } :root { --bg: hsl(0 0% 90%); --nav: hsl(0 0% 100%); --color: hsl(0 0% 30%); } :root.dark { --bg: hsl(0 0% 0%); --nav: hsl(0 0% 14%); --color: hsl(0 0% 90%); } body { place-items: center; min-height: 100vh; font-family: "SF Pro Text", "SF Pro Icons", "AOS Icons", "Helvetica Neue", Helvetica, Arial, sans-serif, system-ui; background: var(--bg); color: var(--color); } nav { height: 60px; position: sticky; top: 0; left: 0; right: 0; text-transform: uppercase; font-family: monospace; font-size: 14px; background: var(--nav); } .nav__content { width: 1100px; display: flex; max-width: calc(100% - 2rem); margin: 0 auto; height: 100%; gap: 1rem; position: relative; justify-content: space-between; background: var(--nav); } .nav__control { width: 60px; } label { display: grid; place-items: center; height: 100%; width: 100%; cursor: pointer; } .nav__control svg { width: 24px; stroke-width: 2.5; rotate: calc(var(--active-nav, 0) * 45deg); transition: rotate var(--speed); } input:focus-visible + label { outline: 1px solid red; } .nav__content > a svg { width: 32px; /* color: hsl(0 0% 15%);*/ } .sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border-width: 0; } .nav__options a { position: relative; padding: 1rem 2rem; height: 60px; } .nav__options svg { height: 16px; stroke-width: 2.5px; } .nav__options { position: absolute; right: -1rem; top: 100%; background: var(--nav); width: calc(100% + 2rem); translate: 0 calc(-100% + (var(--active-nav, 0) * (100% + 2px))); transition: translate var(--speed); z-index: -1; } a:focus-visible { outline: 1px solid red; } :root:has(#menu:checked) { --active-nav: 1; } .nav__options a:not(:last-of-type) { border-bottom: 2px solid var(--bg ); } nav a { display: flex; place-items: center; padding: 1rem; text-decoration: none; justify-content: space-between; color: currentColor; } nav a:is(:hover, :focus-visible) { --active: 1; } .link svg { opacity: var(--active, 0); rotate: calc(var(--active, 0) * -45deg); scale: calc(1 + (var(--active, 0) * 0.1)); transition: opacity calc(var(--speed) * 1.5), rotate var(--speed), scale var(--speed); } .ebook { display: none; } @media(min-width: 1200px) { .ebook { display: flex; } } /* The :hover stuff */ :root { --speed: 0.25s; } @media(min-width: 768px) { :root { --lerp-0: 1; /* === sin(90deg) */ --lerp-1: calc(sin(30deg)); --lerp-2: calc(sin(20deg)); --lerp-3: calc(sin(10deg)); --lerp-4: 0; --speed: 0.25s; } .nav__control { display: none; } .nav__options { flex: 1; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; position: static; width: auto; translate: 0 0; z-index: .........完整代码请登录后点击上方下载按钮下载查看
网友评论0