CSS动画(动态导航栏)
1.项目简介
一个具有创意的导航菜单不仅能为你的大作业增色,还能展示你的技术实力。本文将分享一系列常用于期末大作业的CSS动画导航效果,这些效果不仅外观酷炫,而且易于实现。我们提供了一键复制的代码,让你能够快速集成到自己的项目中,节省时间,提高效率,让你的期末大作业脱颖而出。
2.完整代码
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" type="text/css" href="6_21.css">
</head>
<body>
<nav>
<!-- 导航栏按钮,用于主要页面导航 -->
<nav>
<!-- 主页按钮,包含文本和图标表示 -->
<button type="button" title="Home">
<span>Home</span>
<!-- 使用Material Symbols Outline图标的HTML代码,用于增强视觉效果 -->
<span class="material-symbols-outlined" aria-hidden="true">首页</span>
<!-- SVG图形用于呈现"Home"文本的视觉效果,aria-hidden属性表示此元素不用于屏幕阅读器 -->
<svg viewBox="0 0 300 300" aria-hidden="true">
<g>
<!-- 使用textPath元素将文本沿着路径绘制 -->
<text fill="currentColor">
<textPath xlink:href="#circlePath">Home</textPath>
</text>
<text fill="currentColor">
<textPath xlink:href="#circlePath" startOffset="50%">Home</textPath>
</text>
</g>
</svg>
</button>
<!-- 关于按钮,包含文本和图标表示 -->
<button type="button">
<span>About</span>
<span class="material-symbols-outlined" aria-hidden="true">信息</span>
<svg viewBox="0 0 300 300" aria-hidden="true">
<g>
<text fill="currentColor">
<textPath xlink:href="#circlePath">About</textPath>
</text>
<text fill="currentColor">
<textPath xlink:href="#circlePath" startOffset="50%">About</textPath>
</text>
</g>
</svg>
</button>
<!-- 服务按钮,包含文本和图标表示 -->
<button type="button">
<span>Services</span>
<span class="material-symbols-outlined" aria-hidden="true">服务</span>
<svg viewBox="0 0 300 300" aria-hidden="true">
<g>
<text fill="currentColor">
<textPath xlink:href="#circlePath">Services</textPath>
</text>
<text fill="currentColor">
<textPath xlink:href="#circlePath" startOffset="50%">Services</textPath>
</text>
</g>
</svg>
</button>
<!-- 联系按钮,包含文本和图标表示 -->
<button type="button">
<span>concat</span>
<span class="material-symbols-outlined" aria-hidden="true">联系</span>
<svg viewBox="0 0 300 300">
<g>
<text fill="currentColor" aria-hidden="true">
<textPath xlink:href="#circlePath">Contact</textPath>
</text>
<text fill="currentColor">
<textPath xlink:href="#circlePath" startOffset="50%">Contact</textPath>
</text>
</g>
</svg>
</button>
</nav>
<!-- SVG 模板与动态文本 -->
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
viewBox="0 0 300 300" width="0" height="0">
<defs>
<path id="circlePath" d="M 150, 150 m -50, 0 a 50,50 0 0,1 100,0 a 50,50 0 0,1 -100,0" />
</defs>
</svg>
</body>
</html>
CSS
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
/* 重置按钮样式 */button {
appearance: none;
background-color: transparent;
border: none;
cursor: pointer;
outline: none;
padding: 0;
margin: 0;
font-family: inherit;
font-size: inherit;
color: inherit;
text-decoration: none;
text-transform: none;
line-height: normal;
overflow: visible;
}
body {
min-height: 100svh;
background-color: rgb(15, 23, 42);
color: white;
display: grid;
place-content: center;
font-size: 1rem;
font-family: system-ui;
}
nav {
--_clr-txt: rgb(255, 255, 255);
--_clr-txt-svg: rgb(147, 158, 184);
--_ani-speed: 6s;
/* 旋转文本的速度 */
display: flex;
/*flex-wrap: wrap;*/
gap: 1rem;
font-size: 1.4rem;
}
nav>button {
position: relative;
display: grid;
place-content: center;
grid-template-areas: 'stack';
padding: 0 1.5rem;
text-transform: uppercase;
font-weight: 300;
}
/* 将按钮元素堆叠在一起 */nav>button>span {
transition: all 300ms ease-in-out;
grid-area: stack;
}
/* 导航图标 */nav>button>span:last-of-type {
margin-top: 0.25rem;
transform: scale(0);
transition-delay: 0ms;
border-radius: 50%;
}
/* 悬停 - 隐藏文本 */nav>button:focus-visible>span:first-of-type,
nav>button:hover>span:first-of-type {
transform: scale(0);
}
/* 悬停 - 显示图标 */nav>button:focus-visible>span:last-of-type,
nav>button:hover>span:last-of-type {
transform: scale(1);
}
/* 导航 SVG 圆形文本 */nav>button>svg {
position: absolute;
width: 200px;
height: 200px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
transform-origin: center;
opacity: 0;
text-transform: uppercase;
transition: all 300ms ease-in-out;
color: var(--_clr-txt-svg);
}
/* 悬停 - 显示旋转的 SVG */nav>button:focus-visible>svg,
nav>button:hover>svg {
transform: translate(-50%, -50%) scale(1);
opacity: 1;
transition-delay: 150ms;
transition: all 300ms ease-in-out;
}
/*
@supports (-webkit-touch-callout: none) {
/* 特定于 iOS 设备 * /button svg {
/* 调整 iOS 设备的位置 * /translate: -50% -50%;
animation: rotate var(--_ani-speed) linear infinite;
}
}
@supports not (-webkit-touch-callout: none) {
*/
button svg g {
transform-origin: center;
animation: rotate var(--_ani-speed) linear infinite;
}
@keyframes rotate {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
CSS动画(动态导航栏)的更多相关文章
- 【源码分享】jquery+css实现侧边导航栏
jquery+css实现侧边导航栏 最近做项目的时候,突然想用一个侧边导航栏,网上找了几个插件,有的太丑而且不太符合我的预期.与其修改别人的代码,不如自己来写一个了.废话不多说先上图,感兴趣的请继续看 ...
- Jquery实现动态导航栏和轮播导航栏
动态导航栏和轮播导航栏的实现思想: 利用jquery技术的append()方法和bind()方法实现li标签的添加和点击事件绑定,在利用$getJSON(url,data,function)请求方法实 ...
- 动态导航栏和JavaScript箭头函数
动态导航栏和JavaScript箭头函数 今天我们来写一下动态的导航栏,并且学一下JavaScript的箭头函数等相关问题. 样式如下所示: html中执行代码如下所示: <!DOCTYPE h ...
- CSS实现动画特效导航栏
0 写在前面 今天用纯CSS编写了一种带有特效的导航栏,一方面巩固熟悉了导航栏的一般写法,另一方面练习了CSS3的一些新特性. 1 实现效果 当鼠标划过时,实现了一种动态百叶窗效果. 2 实现细节 2 ...
- 巧妙使用checkbox制作纯css动态导航栏
前提:很多时候.我们的网页都需要一个垂直的导航栏.可以分类.有分类.自然就有展开.关闭的功能.你还在使用jquery操作dom来制作吗?那你就out了! 方案:使用checkbox 的 checked ...
- HTML和CSS设置动态导航以及CSS中伪元素的简单说明
HTML页面代码: <!DOCTYPE html> <html> <head> <title>Test</title> <meta c ...
- 【温故而知新-CSS】使用CSS设计网站导航栏
body #nav li a { width: auto; } #nav li a:hover { background-color: #ffcc00; color: #fff; border-rig ...
- CSS常用操作-导航栏
1.垂直导航栏 index.html <!DOCTYPE html> <html> <head> <meta charset="UTF-8" ...
- html+css 制作简易导航栏
二话不说直接上代码(萌新:实在也没什么好说的) <!DOCTYPE html> <html lang="en" xmlns="http://www.w3 ...
- jsp动态导航栏
站点页面的导航栏是从数据库中生成出来的,所以在界面上展示导航栏时,要从数据库中读取出来,但不能每次显示一个页面都从数据库中读.这样就非常浪费性能.应该考虑把导航栏放到一个缓存中.如:session.a ...
随机推荐
- 强化学习分布式经验回放框架(experience replay)reverb的安装
框架reverb的相关介绍: https://www.cnblogs.com/devilmaycry812839668/p/16260799.html ======================== ...
- 面向分布式强化学习的经验回放框架——Reverb: A Framework for Experience Replay
论文题目: Reverb: A Framework for Experience Replay 地址: https://arxiv.org/pdf/2102.04736.pdf 框架代码地址: htt ...
- 实验室服务彻底死机记录——硬件故障——主板pcie槽坏掉或显卡坏掉
2022年11月8日 后记(最新更新) 服务器送售后,售后给厂家技术打电话,厂家技术说可能是显卡的电源线松了,于是我们打开机箱把显卡的电源线紧了紧,然后神奇的事情发生了,故障解除了...... 一 ...
- 通过内存映射的方式向lcd屏幕输出几个圆
/************************************************* * * file name:color.c * author :momolyl@126.com * ...
- LemurBrowser狐猴浏览器:支持插件扩展、内置免费AI工具的移动端浏览器
如何选择一款合适的浏览器? 在这个数字化时代,浏览器作为互联网的入口.然而,选择一款合适的浏览器却并不容易. 注释:狐猴浏览器是浏览器新标签页插件Wetab提供的支持在移动端安装插件,内置免费AI工具 ...
- Vim 全局配置 / 设置鼠标模式
新搞的 Linux (Debian) 上的 vim 一右击粘贴就变成 insert (Visual) 模式,上网查了一下,要 set mouse=,但是每次设置太麻烦了,另外我也想改一下全局配色. 定 ...
- 热力学平衡、Liftshitz 理论和朗道理论
科学家们经过广泛的实验发现:熔化往往始于固体表面.熔化时,体系由 "固体-气体接触" 变为 "固体-熔化层接触 + 熔化层-气体接触".如果后者的能量更稳定,则 ...
- 异源数据同步 → DataX 为什么要支持 kafka?
开心一刻 昨天发了一条朋友圈:酒吧有什么好去的,上个月在酒吧当服务员兼职,一位大姐看上了我,说一个月给我 10 万,要我陪她去上海,我没同意 朋友评论道:你没同意,为什么在上海? 我回复到:上个月没同 ...
- 修改 Ubuntu 文件夹为英文
如果你在安装 Ubuntu 时,语言选了中文,那么系统自动创建的文件夹也会是中文(下载.图片 等).有时这会造成不便.可以通过以下命令将文件夹改为英文: LANG=C LC_ALL=C xdg-use ...
- 在 Docker 中启动 Jupyter
参考:Jupyter Docker Stacks documentation 容器地址在 quay.io/jupyter/scipy-notebook 如果你直接运行命令: docker run -p ...