css3 实现html样式蛇形布局

文章目录

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

1. 实现效果

2. 实现代码

html 复制代码
<template>
  <div class="body">
    <div class="title">CSS3实现蛇形布局</div>
    <div class="list">
      <div class="item" v-for="(item, index) in 20" :style="`--i: ${index}`">
        <span>{{ index + 1 }}</span>
      </div>
    </div>
  </div>
</template>

<script>
export default {};
</script>

<style lang="scss" scoped>
.body {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #de3730;
  .title {
    font-size: 25px;
    font-weight: bold;
    color: #fff;
  }
  .list {
    padding: 20px;
    display: flex;
    width: 100vw;
    gap: 40px;
    flex-wrap: wrap;
    .item {
      width: calc((100% - 120px) / 4);
      background: #00c297;
      color: #fff;
      font-size: 30px;
      border-radius: 5px;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      order: var(--i);
      padding: 10px;
      position: relative;
      span {
        text-align: center;
        font-size: 40px;
        font-weight: bold;
      }
      &::after {
        position: absolute;
        content: "=>";
        width: 18px;
        display: inline-block;
        font-size: 12px;
        top: 50%;
        transform: translateY(-50%);
        right: -30px;
        z-index: 1;
        color: #fff;
        font-weight: bold;
        font-size: 18px;
      }
      &:nth-child(8n + 5) {
        order: calc(var(--i) + 3);
      }
      &:nth-child(8n + 6) {
        order: calc(var(--i) + 1);
      }
      &:nth-child(8n + 7) {
        order: calc(var(--i) - 1);
      }
      &:nth-child(8n + 8) {
        order: calc(var(--i) - 3);
      }
      &:nth-child(8n + 4),
      &:nth-child(8n + 8) {
        &::after {
          position: absolute;
          left: 50%;
          top: 110%;
          font-weight: bold;
          transform: translateX(-50%) rotate(90deg);
        }
      }
      &:nth-child(8n + 5),
      &:nth-child(8n + 6),
      &:nth-child(8n + 7) {
        &::after {
          left: -32px;
          top: 50%;
          transform: rotate(180deg) translateY(50%);
        }
      }
      &:last-child {
        &::after {
          display: none;
        }
      }
    }
  }
}
</style>
相关推荐
星环科技5 分钟前
数据标准Agent ,让企业数据说同一种语言
java·开发语言·前端
Odoo老杨6 分钟前
如何直接在线定制修改 Odoo UI界面?
css·python·crm·odoo·erp·中小企业数字化
橘子星10 分钟前
深入理解 AJAX 中的 JSON 序列化与 JS 异步处理
前端·javascript·后端
旧曲重听114 分钟前
2026前端技术从「夯」到「拉」
前端·程序人生·职场和发展·软件工程
Kapaseker14 分钟前
我找到了最适合程序员的 PPT 工具 — Slidev
前端
夏幻灵20 分钟前
深度解析 JavaScript 异步编程:从回调地狱到 Promise 的重构
开发语言·javascript·重构
雾削木31 分钟前
B语言经典教程现代化重构
java·前端·stm32·单片机·嵌入式硬件
Cobyte33 分钟前
20.Vue Vapor 的应用初始化
前端·javascript·vue.js
乘风gg37 分钟前
手把手带你实践历时一年总结的 AI Code Review 最佳工作流!
前端·ai编程·cursor
禅思院37 分钟前
POST请求发两次?一次讲透CORS预检机制,面试不再翻车
前端·架构·前端框架