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

1. 实现效果

在这里插入图片描述

2. 实现代码

<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>

相关推荐

  1. js+css实现手风琴

    2024-04-12 05:34:08       58 阅读
  2. vue 滚动美化 css

    2024-04-12 05:34:08       38 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-12 05:34:08       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-12 05:34:08       106 阅读
  3. 在Django里面运行非项目文件

    2024-04-12 05:34:08       87 阅读
  4. Python语言-面向对象

    2024-04-12 05:34:08       96 阅读

热门阅读

  1. 减少服务器被入侵

    2024-04-12 05:34:08       48 阅读
  2. 阿里云(国内)安装nvm

    2024-04-12 05:34:08       40 阅读
  3. ocr+sha256

    2024-04-12 05:34:08       128 阅读
  4. Spring Boot 连接 RabbitMQ

    2024-04-12 05:34:08       189 阅读
  5. ELK Stack、Kafka 和 Filebeat 认识和使用上手

    2024-04-12 05:34:08       106 阅读
  6. 浅谈:从医疗元宇宙向更多实业领域的拓展

    2024-04-12 05:34:08       40 阅读
  7. Ubuntu Desktop Server 快捷键

    2024-04-12 05:34:08       42 阅读
  8. flutter嵌入原生view

    2024-04-12 05:34:08       33 阅读
  9. 22、Lua 数据库访问

    2024-04-12 05:34:08       40 阅读