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>
相关推荐
qiyi.sky3 分钟前
JavaWeb——Vue组件库Element(3/6):常见组件:Dialog对话框、Form表单(介绍、使用、实际效果)
前端·javascript·vue.js
煸橙干儿~~6 分钟前
分析JS Crash(进程崩溃)
java·前端·javascript
哪 吒8 分钟前
华为OD机试 - 几何平均值最大子数(Python/JS/C/C++ 2024 E卷 200分)
javascript·python·华为od
安冬的码畜日常16 分钟前
【D3.js in Action 3 精译_027】3.4 让 D3 数据适应屏幕(下)—— D3 分段比例尺的用法
前端·javascript·信息可视化·数据可视化·d3.js·d3比例尺·分段比例尺
l1x1n043 分钟前
No.3 笔记 | Web安全基础:Web1.0 - 3.0 发展史
前端·http·html
Q_w77421 小时前
一个真实可用的登录界面!
javascript·mysql·php·html5·网站登录
昨天;明天。今天。1 小时前
案例-任务清单
前端·javascript·css
一丝晨光1 小时前
C++、Ruby和JavaScript
java·开发语言·javascript·c++·python·c·ruby
Front思1 小时前
vue使用高德地图
javascript·vue.js·ecmascript
zqx_72 小时前
随记 前端框架React的初步认识
前端·react.js·前端框架