css实现菜单悬浮展开效果代码
代码语言:html
所属分类:悬停
代码描述:css实现菜单悬浮展开效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> @import url(//repo.bfw.wiki/bfwrepo/css/open-props.min.css); @import url(//repo.bfw.wiki/bfwrepo/css/open-props.normalize.min.css); * { box-sizing: border-box; } body { display: grid; place-items: center; min-height: 100vh; background: var(--gray-12); } ul { padding: 0; display: inline-grid; grid-auto-flow: column; list-style-type: none; grid-template-columns: auto repeat(3, calc((var(--active, 0) * 130px) + 10px)); transition: grid-template-columns 0.35s var(--ease-elastic-1); transition: grid-template-columns 0.35s var(--ease-elastic-1), -ms-grid-columns 0.35s var(--ease-elastic-1); } main { width: 66ch; } li { display: grid; justify-content: end; z-index: calc(var(--count) - var(--index)); } nav { position: relative; } nav > button { position: absolute; left: 0; background: red; z-index: var(--count); } a { background: hsl(0 0% 60% / 0.18); display: inline-block; padding: var(--size-2) var(--size-4); border-radius: var(--radius-5); margin: 0; color: var(--gray-0); font-size: var(--font-size-1); font-weight: var(--font-weight-0); -webkit-backdrop-filter: blur(40px); backdrop-filter: blur(40px); transition: color 0.2s, background 0.2s; } a:visited { color: var(--gray-0); } svg { height: 24px; aspect-ratio: 1; fill: currentColor; } span { display: grid; align-items: center; grid-auto-flow: column; grid-template-columns: 16px 1fr; gap: 0.25rem; } li:is( :nth-of-type(2), :nth-of-type(3), :nth-of-type(4) ) span { opacity: var(--active, 0); } li:is( :nth-of-type(2), :nth-of-type(3), :nth-of-type(4) ) a:is(:hover, :focus) { background: var(--gray-0); color: var(--gray-12); } a:focus-visible { outline-color: transparent; } ul:is(:focus-within, :hover) { --active: 1; } </style> </head> <body > <main> <nav style="--count: 4;"> <ul> <li style="--index: 1;"> <a href="#" target="_blank" rel="noreferrer noopener"> <span><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6"> <path stroke-linecap="round" stroke-linejoin="round" d="M15.75 6a3.75 3.75 0 11-7.5 0 3.75 3.75 0 017.5 0zM4.501 20.118a7.5 7.5 0 0114.998 0A17.933 17.933 0 0112 21.75c-2.676 0-5.216-.584-7.499-1.632z" /> </svg> Socials</span> </a> </li> <li style="--index: 2;"> <a href="" target="_blank" rel="noreferrer noopener"> <span> <svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Twitter</title><path d="M23.953 4.57a10 10 0 01-2.825.775 4.958 4.958 0 002.163-2.723c-.951.555-2.005.959-3.127 1.184a4.92 4.92 0 00-8.384 4.482C7.69 8.095 4.067 6.13 1.64 3.162a4.822 4.822 0 00-.666 2.475c0 1.71.87 3.213 2.188 4.096a4.904 4.904 0 01-2.228-.616v.06a4.923 4.923 0 003.946 4.827 4.996 4.996 0 01-2.212.085 4.936 4.936 0 004.60.........完整代码请登录后点击上方下载按钮下载查看
网友评论0