CSS动画(动态导航栏)

2024-06-22 17:52

本文主要是介绍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动画(动态导航栏)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1084998

相关文章

vue, 左右布局宽,可拖动改变

1:建立一个draggableMixin.js  混入的方式使用 2:代码如下draggableMixin.js  export default {data() {return {leftWidth: 330,isDragging: false,startX: 0,startWidth: 0,};},methods: {startDragging(e) {this.isDragging = tr

vue项目集成CanvasEditor实现Word在线编辑器

CanvasEditor实现Word在线编辑器 官网文档:https://hufe.club/canvas-editor-docs/guide/schema.html 源码地址:https://github.com/Hufe921/canvas-editor 前提声明: 由于CanvasEditor目前不支持vue、react 等框架开箱即用版,所以需要我们去Git下载源码,拿到其中两个主

React+TS前台项目实战(十七)-- 全局常用组件Dropdown封装

文章目录 前言Dropdown组件1. 功能分析2. 代码+详细注释3. 使用方式4. 效果展示 总结 前言 今天这篇主要讲全局Dropdown组件封装,可根据UI设计师要求自定义修改。 Dropdown组件 1. 功能分析 (1)通过position属性,可以控制下拉选项的位置 (2)通过传入width属性, 可以自定义下拉选项的宽度 (3)通过传入classN

js+css二级导航

效果 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Con

基于Springboot + vue 的抗疫物质管理系统的设计与实现

目录 📚 前言 📑摘要 📑系统流程 📚 系统架构设计 📚 数据库设计 📚 系统功能的具体实现    💬 系统登录注册 系统登录 登录界面   用户添加  💬 抗疫列表展示模块     区域信息管理 添加物资详情 抗疫物资列表展示 抗疫物资申请 抗疫物资审核 ✒️ 源码实现 💖 源码获取 😁 联系方式 📚 前言 📑博客主页:

vue+el国际化-东抄西鉴组合拳

vue-i18n 国际化参考 https://blog.csdn.net/zuorishu/article/details/81708585 说得比较详细。 另外做点补充,比如这里cn下的可以以项目模块加公共模块来细分。 import zhLocale from 'element-ui/lib/locale/lang/zh-CN' //引入element语言包const cn = {mess

vue同页面多路由懒加载-及可能存在问题的解决方式

先上图,再解释 图一是多路由页面,图二是路由文件。从图一可以看出每个router-view对应的name都不一样。从图二可以看出层路由对应的组件加载方式要跟图一中的name相对应,并且图二的路由层在跟图一对应的页面中要加上components层,多一个s结尾,里面的的方法名就是图一路由的name值,里面还可以照样用懒加载的方式。 页面上其他的路由在路由文件中也跟图二是一样的写法。 附送可能存在

vue+elementUI下拉框联动显示

<el-row><el-col :span="12"><el-form-item label="主账号:" prop="partyAccountId" :rules="[ { required: true, message: '主账号不能为空'}]"><el-select v-model="detailForm.partyAccountId" filterable placeholder="

vue+elementui分页输入框回车与页面中@keyup.enter事件冲突解决

解决这个问题的思路只要判断事件源是哪个就好。el分页的回车触发事件是在按下时,抬起并不会再触发。而keyup.enter事件是在抬起时触发。 so,找不到分页的回车事件那就拿keyup.enter事件搞事情。只要判断这个抬起事件的$event中的锚点样式判断不等于分页特有的样式就可以了 @keyup.enter="allKeyup($event)" //页面上的//js中allKeyup(e

vue子路由回退后刷新页面方式

最近碰到一个小问题,页面中含有 <transition name="router-slid" mode="out-in"><router-view></router-view></transition> 作为子页面加载显示的地方。但是一般正常子路由通过 this.$router.go(-1) 返回到上一层原先的页面中。通过路由历史返回方式原本父页面想更新数据在created 跟mounted