012:vue结合纯CSS实现蛇形流程图/步骤条

文章目录

  • [1. 实现效果](#1. 实现效果)
  • [2. 实现代码](#2. 实现代码)

1. 实现效果

2. 实现代码

html 复制代码
<template>
  <div class="container">
    <div v-for="(item, index) in list" class="grid-item">
      <div class="step">step{{index+1}}</div>
    </div>
  </div>
</template>

<script setup>
  import { ref } from 'vue';

const list = ref(new Array(11).fill(''));
</script>

<style lang="less">
  /** 可配置的参数 可以调整试试 */
  @colNum: 4; // 单行排列的步骤 试试 2、3、4、5、6
  @colEven: @colNum * 2; // 两行元素数
  @lineWidth: 26px; // 步骤间连线长度
  @rowDistance: 40px; // 行间距
  @colDistance: @lineWidth; // 列间距
  @arrowSize: 6px; // 箭头大小
  @stepColor: #cfbbfd; // 步骤颜色

  .container {
    margin-top:100px;
    display: grid;
    grid-template-columns: repeat(@colNum, 1fr);
    gap: @rowDistance @colDistance;
    padding-top: @rowDistance;
  }

  .grid-item {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;

    &::before {
      position: absolute;
      content: '';
      right: -@lineWidth;
      width: @lineWidth;
      height: 0;
      border-top: 1px dashed @stepColor;
    }

    &::after {
      content: '';
      position: absolute;
      right: (-@colDistance / 2);
      transform: translateX(50%);
      border-top: (@arrowSize / 1.4) solid transparent;
      border-left: @arrowSize solid @stepColor;
      border-bottom: (@arrowSize / 1.4) solid transparent;
    }

    // 给每行最后一个步骤(除最后一行)添加向下的连接箭头
    &:nth-child(@{colNum}n) {

      &:not(:last-child) {
        .step {
          &::before {
            content: '';
            position: absolute;
            left: 50%;
            bottom: -(@rowDistance / 2);
            height: @lineWidth;
            border-left: 1px dashed @stepColor;
            transform: translate(-50%, 50%);
          }

          &::after {
            content: '';
            position: absolute;
            left: 50%;
            bottom: -(@rowDistance / 2);
            border-top: @arrowSize solid @stepColor;
            border-left: (@arrowSize / 1.4) solid transparent;
            border-right: (@arrowSize / 1.4) solid transparent;
            transform: translate(-50%, 50%);
          }
        }
      }
    }

    each(range(@colEven), {
        &:nth-child(@{colEven}n+@{value}) {
          @isEvenLine: boolean(@value > @colNum);
          @modNum: mod(@value, @colEven); // 余数 1、2、3、4、5、0
          color: if(@isEvenLine, #7dbcf7, #f38cd6);

          /** 偶数行旋转箭头,步骤倒序排列(使用transform交换位置) */
          & when (@isEvenLine) {
            @transN: (@colNum + 1 + @colEven - @value - @value);
            transform: translateX(calc(@transN * 100% + @transN * @colDistance));

            &::after {
              transform: translateX(50%) rotate(180deg) !important; // 旋转箭头
            }
          }

          // 最右排(n & n + 1 位)隐藏多余的箭头(如果container设置了overflow:hidden 则不用处理)
          & when (@modNum=@colNum), (@modNum=@colNum+1) {
            &::before, &::after {
              display: none;
            }
          }

          // 最后一个步骤在奇数行 需要隐藏连线箭头
          & when not (@isEvenLine) {
            &:last-child {
              &::before, &::after {
                display: none;
              }
            }
          }

        }
      }

    )
  }

  .step {
    position: relative;
    width: 100px;
    line-height: 30px;
    font-size: 16px;
    text-align: center;
    border: 1px solid @stepColor;
    border-radius: 4px;
  }
</style>
相关推荐
燕落南枝6 小时前
CSS 学习:类型选择器与 AI 注释实战
css·人工智能·学习
Java后端的Ai之路11 小时前
前端技术Vue-09-webpack-vuejs-实战
前端·vue.js·webpack
燕落南枝13 小时前
CSS 类选择器详解:从入门到实战
前端·css
tryCbest13 小时前
Vue3——第 7 篇:组件基础——从注册到使用的完整流程
前端·javascript·vue.js
weixin_BYSJ198713 小时前
【计算机毕设】房屋租赁系统02647
java·vue.js·spring boot·python·django·课程设计
时间的情敌13 小时前
Electron 设置-webkit-app-region: drag;实现拖拽后, 无法响应鼠标划过事件及点击事件的解决方式
前端·vue.js
专业程序开发源14 小时前
springboot校企合作双选会一站式预约与面试系统16010-计算机课程设计、毕业设计
java·vue.js·spring boot·后端·面试·php·课程设计
iCxhust15 小时前
模型:500kW飞轮 10kV输电线路 油田抽油机 同时考虑无功补偿 统计:全年节电量 结果56万度电
前端·css·css3·电力·飞轮
凯凯姜16 小时前
Vue 3 深入学习笔记 16:API 请求封装与统一错误处理
vue.js·笔记·学习
Java后端的Ai之路17 小时前
前端框架Vue-07_原生的Vue.js
前端·vue.js·前端框架