当前位置: 首页 > news >正文

带有滑动菜单指示器的纯 CSS 导航选项卡

效果展示

在这里插入图片描述

CSS 知识点

  • filter 属性回顾

  • transition 属性回顾

  • 使用单选框实现导航菜单的思路

    单选框当点击完成后就会有一个:checked属性,可以利用这个属性来实现导航菜单底部滑动块的滑动动画和当前菜单项激活状态的管理。

整体页面结构

<div class="tabs"><!-- 单选 --><input type="radio" id="home" name="tabsMenu" /><input type="radio" id="profile" name="tabsMenu" /><input type="radio" id="likes" name="tabsMenu" /><input type="radio" id="settings" name="tabsMenu" /><input type="radio" id="notifications" name="tabsMenu" /><!-- 图标 --><div class="buttons"><label for="home"><i class="fa-solid fa-house"></i></label><label for="profile"><i class="fa-solid fa-user"></i></label><label for="likes"><i class="fa-solid fa-heart"></i></label><label for="settings"><i class="fa-sharp fa-solid fa-gear"></i></label><label for="notifications"><i class="fa-solid fa-bell"></i></label><!-- 滑块 --><div class="underline"></div></div>
</div>

实现整体布局

.tabs input {visibility: hidden;display: none;
}.buttons {position: relative;display: flex;gap: 80px;padding: 30px 40px;border-bottom: 1px solid rgba(255, 255, 255, 0.2);background: #182d3c;overflow: hidden;border-radius: 20px;
}

编写菜单图标激活后的样式

.buttons label {width: 20%;font-size: 1.75em;-webkit-text-stroke: 1px #fff;color: transparent;cursor: pointer;transition: 0.5s;
}.buttons label:hover {opacity: 1;filter: drop-shadow(0 0 10px #fff) drop-shadow(0 0 20px #fff);
}/* 通过单选框激活状态,设置图标的激活状态 */
.tabs input:nth-child(1):checked ~ .buttons label:nth-child(1),
.tabs input:nth-child(2):checked ~ .buttons label:nth-child(2),
.tabs input:nth-child(3):checked ~ .buttons label:nth-child(3),
.tabs input:nth-child(4):checked ~ .buttons label:nth-child(4),
.tabs input:nth-child(5):checked ~ .buttons label:nth-child(5) {color: #fff;opacity: 1;filter: drop-shadow(0 0 10px #fff) drop-shadow(0 0 20px #fff);
}

实现菜单底部块的样式和移动样式

.underline {position: absolute;left: 0;bottom: 0;width: 20%;height: 5px;/* 设置滑块的移动时间 */transition: 0.5s;
}.underline::before {content: "";position: absolute;left: 50%;transform: translateX(-50%);width: 40px;height: 100%;background: #fff;filter: drop-shadow(0 0 10px #fff) drop-shadow(0 0 20px #fff) drop-shadow(0 0 30px #fff) drop-shadow(0 0 50px #fff);
}.underline::after {content: "";position: absolute;left: 50%;transform: translateX(-50%);width: 40px;height: 100%;background: #fff;filter: drop-shadow(0 0 10px #fff) drop-shadow(0 0 20px #fff) drop-shadow(0 0 30px #fff) drop-shadow(0 0 50px #fff) blur(5px);
}/* 通过单选框激活状态,设置滑块的移动距离 */
.tabs input:nth-child(1):checked ~ .buttons .underline {left: 0;
}.tabs input:nth-child(2):checked ~ .buttons .underline {left: 20%;
}.tabs input:nth-child(3):checked ~ .buttons .underline {left: 40%;
}.tabs input:nth-child(4):checked ~ .buttons .underline {left: 60%;
}.tabs input:nth-child(5):checked ~ .buttons .underline {left: 80%;
}

完整代码下载

完整代码下载

http://www.lryc.cn/news/223563.html

相关文章:

  • Java学习笔记41——接口组成更新
  • iview实现table里面每行数据的跳转
  • Docker快速搭建Drupal内容管理系统并远程访问
  • Ansible优化大全
  • Python|OpenCV-图像的添加和混合操作(8)
  • Vue3+vite+cesium环境搭建
  • metaObjecthandler 的基本理解与使用(自动插入更新人和创建人)
  • SpringBoot与ES7实现多条件搜索
  • 【排序算法】 快速排序(快排)!图解+实现详解!
  • 急招开发、安全工程师实习生
  • 数据结构与算法—插入排序选择排序
  • 基于词云图的短信热词数据可视化
  • Linux/centos上如何配置管理Web服务器?
  • Java EE进阶2
  • 最新AI系统ChatGPT源码+AI绘画系统源码+支持GPT4.0+Midjourney绘画+搭建部署教程+附源码
  • 大厂面试题-为什么一线互联网公司严禁使用存储过程
  • SpringBoot+Swagger详细使用方法
  • [动态规划] (十二) 简单多状态 LeetCode 213.打家劫舍II
  • 算法与数据结构之链表
  • 深入剖析React Hooks中的 useCallback
  • 微服务中配置文件(YAML文件)和项目依赖(POM文件)的区别与联系
  • Java快速排序算法、三路快排(Java算法和数据结构总结笔记)[7/20]
  • 【React】05.JSX语法使用上的细节
  • LeetCode 1759. 统计同质子字符串的数目【字符串】1490
  • FPGA UDP RGMII 千兆以太网(2)IDDR
  • chrome安装vue devtools
  • 【Docker】iptables命令的使用
  • Flex bison 学习好代码
  • 学习Nginx配置
  • 怎么批量获取文件名,并保存到excel?