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

CSS:导航栏三角箭头

用CSS实现导航流程图的样式。可根据自己的需求进行修改,代码精略的写了一下。

注:场景一和场景二在分辨率比较低的情况下会有一个1px的缝隙不太优雅,自行处理。有个方法是直接在每个外面包一个DIV,用动态样式设置底色。

场景一、实现效果图的导航栏

代码部分:

/** 组件:步骤条样式 */ const StepModel = (list: any) => { return ( <> <div className={styles.step}> {list.map((item: any) => { return ( <div className={`${styles.stepMenu} ${ item.success ? styles.successText : styles.defaultText } ${item.status ? styles.stepMenuActive : ''}`} > {item.success ? ( <> <div className={`${styles.icon} ${styles.iconSuccess}`}> <img src={require(`@/assets/imgs/success.png`)} alt="" /> </div> </> ) : ( <> <img className={styles.icon} src={require(`@/assets/imgs/${ item.activeIcon ? item.activeIcon : item.icon }.png`)} alt="" /> </> )} {item.name} </div> ); })} </div> </> ); }; /** 组件样式 */ .step { width: 100%; height: 32px; margin-top: 8px; font-size: 12px; font-weight: 400; display: flex; justify-content: space-between; filter: drop-shadow(-1px 1px 9px rgba(8, 38, 55, 0.1)); .successText { color: #222222; } .defaultText { color: #788295; } .stepMenu { padding: 0px 10px 0 30px; line-height: 32px; background: white; display: flex; align-items: center; position: relative; flex-basis: calc((100%) / 5); .icon { width: 16px; height: 16px; margin-right: 8px; } .iconSuccess { background: #00b864; border-radius: 50%; display: flex; align-items: center; justify-content: center; } } /** 箭头样式 */ .stepMenu:after { content: ''; display: block; position: absolute; right: -11px; top: 5px; z-index: 10; border-left: 15px solid white; border-top: 7px solid white; border-right: 7px solid transparent; border-bottom: 15px solid transparent; transform: rotate(135deg); border-top-left-radius: 6px; filter: drop-shadow(-3px -4px 2px rgba(8, 38, 55, 0.1)); } /** 选中样式 */ .stepMenuActive { color: #fff; background: linear-gradient(to right, #60c9fc, #296be8); font-weight: 700; } /** 选中样式:箭头 */ .stepMenuActive:after { border-left: 16px solid #296be8; border-top: 7px solid #296be8; border-right: 7px solid transparent; border-bottom: 16px solid transparent; } /** first 样式加圆角 */ .stepMenu:first-child { border-radius: 4px 0 0 4px; padding-left: 18px; } /** last 样式加圆角 */ .stepMenu:last-child { border-radius: 0px 4px 4px 0px; padding-right: 18px; } .stepMenu:last-child:after { display: none; } }

场景二:实现效果图

效果图:

代码:直接引入的在线JQ

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>Title</title> <style> body { padding: 50px 20px 0 20px; } .step { width: 100%; height: 32px; margin-top: 8px; font-size: 12px; font-weight: 400; display: flex; justify-content: space-around; } .step > div { padding: 0px 10px 0 30px; line-height: 32px; background: #dceefe; display: inline-block; color: #1e9fff /*#50abe4*/; position: relative; width: 16%; } .step div:after { content: ""; display: block; border-top: 16px solid transparent; border-bottom: 16px solid transparent; border-left: 17px solid #dceefe; position: absolute; right: -17px; top: 0; } .step div:after { content: ""; display: block; border-top: 16px solid transparent; border-bottom: 16px solid transparent; border-left: 17px solid #dceefe; position: absolute; right: -17px; top: 0; z-index: 10; } .step div:before { content: ""; display: block; border-top: 16px solid #dceefe; border-bottom: 16px solid #dceefe; border-left: 17px solid #fff; position: absolute; left: 0px; top: 0; } .step div:first-child { border-radius: 4px 0 0 4px; padding-left: 18px; } .step div:last-child { border-radius: 0px 4px 4px 0px; padding-right: 18px; } .step div:first-child:before { display: none; } .step div:last-child:after { display: none; } .step div.active { background: #1e9fff; color: #fff; } .step div.active:after { border-left-color: #1e9fff; } .step div.active:before { border-top: 16px solid #1e9fff; border-bottom: 16px solid #1e9fff; } </style> </head> <body> <div class="step"> <div class="active">第一步</div> <div>第二步</div> <div>第三步</div> <div>第四步</div> <div>第五步</div> </div> <script src="https://cdn.staticfile.org/jquery/3.6.0/jquery.min.js"></script> <script type="text/javascript"> $(function () { gotoStep(2); }); function gotoStep(step) { $(".step div").removeClass("active"); // 移除所有 div 的 active 类 $(".step div") .eq(step - 1) .addClass("active"); // 给指定索引的 div 添加 active 类 } </script> </body> </html>
http://www.jsqmd.com/news/693219/

相关文章:

  • 2026陕西系统门窗十大品牌权威榜单 - 深度智识库
  • 告别炼丹:用MoCo v3的‘冻结Patch层’技巧,让你的ViT自监督训练稳如老狗
  • 告别复制粘贴:用CANdelaStudio 17从CDDT模板到定制CDD的完整避坑指南
  • 2026年二甲基硅油与有机化工溶剂深度横评:工业原料采购完全指南 - 年度推荐企业名录
  • Houdini POP学习02
  • HC32L130开发避坑实录:从官方Demo到稳定工程,我踩过的那些编译器与库的‘坑’
  • HackGen编程字体完全指南:为什么它是开发者的终极选择
  • 从零构建JavaEE网上书城:MVC架构与购物车系统实战指南
  • 从CUDA到CANN:给NVIDIA开发者的昇腾AscendCL迁移避坑指南
  • Happy Island Designer:终极岛屿规划工具完全指南 [特殊字符]️
  • React Native Modals完整教程:打造滑动关闭和自定义动画的完美弹窗
  • 百万词元的智慧觉醒:DeepSeek-V4如何点亮超长上下文的星辰大海
  • 告别点灯实验:用STM32CubeMX+HAL库5分钟搞定按键控制LED,效率翻倍
  • 英雄联盟皮肤自由切换:R3nzSkin内存换肤技术实战指南
  • 盘点2026年天津宝奥之星奔驰汽车维修,场地大且服务质量好值得选择 - 工业品牌热点
  • Rust的#[derive(Hash)]一致性
  • 游戏性能优化新选择:sguard_limit 如何解决腾讯游戏卡顿问题
  • 别再对着Segmentation fault干瞪眼了!手把手教你用ulimit和kernel.core_pattern捕获Linux核心转储
  • HiveWE:魔兽争霸III终极地图编辑器完整指南
  • 2026年化工废品回收厂家排名,揭秘靠谱品牌及化工塑料桶回收价格 - 工业设备
  • “std::reflect”不是银弹!C++26反射在嵌入式/实时系统中的5大硬伤(中断延迟+4.3μs、LTO失效、调试信息膨胀300%)
  • Flask上下文的魔法:拨开 Application 与 Request 上下文的迷雾
  • ChatGLM2生成内容总卡在‘土耳其土耳其‘?手把手教你用LogitsProcessor解决LLM重复循环问题
  • S905L3-B电视盒子终极改造:从安卓机顶盒到Armbian服务器的深度解锁
  • 如何快速掌握navi:交互式命令行 cheat sheet 工具终极指南
  • Python requests库请求超时?别慌,这3个实战技巧帮你彻底搞定ReadTimeoutError
  • 超强开源贡献指南first-contributions:15分钟搞定首个Pull Request
  • 你还在手动改launch.json?这3行JSON Schema声明让VSCode自动识别容器服务端口并智能映射断点——企业级DevEx提效最后1公里
  • 2026年CNAS资质咨询机构推荐:权威测评与选型指南 - 速递信息
  • 终极指南:掌握Google Objective-C代码风格规范