flex 实现多行项目动态堆叠,随着屏幕尺寸而扩展减少

当您增加或减少屏幕尺寸时,这些 flex 项目会缩小和增长。

html 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .parent {
      display: flex;
      flex-wrap: wrap;
    }

    .parent {
      width: 100%;
      height: 100%;
    }
    .box {
      font-size: 2rem;
      padding: 1rem;
      display: grid;
      place-items: center;
      border-radius: 1rem;
      border-style: dashed;
    }
    .box {
      flex: 1 1 150px;
      flex: 0 1 150px;
      margin: 5px;
    }
  </style>
</head>
<body>
  <div class="ex-container" style="width: 100%; height: 100%; display: flex; justify-content: center; align-items: center;">
    <div class="" style="
      box-sizing: border-box;
      width: 90%;
      height: 100%;
      padding: 20px;
    ">
      <div class="parent white">
        <div class="box green">1</div>
        <div class="box green">2</div>
        <div class="box green">3</div>
        <div class="box green">4</div>
        <div class="box green">5</div>
      </div>
    </div>
  </div>
</body>
</html>

实现效果

相关推荐
软件技术NINI12 小时前
传统文化html+css 5页
前端·css·html
海兰2 天前
【应用】UUID v7 生成器 HTML 代码
css·html·css3
feixing_fx2 天前
告别枯燥字体:Web 字体加载策略与 font-display 最佳实践
前端·css·前端框架·交互·css3
ly76892 天前
CSS 从入门到进阶:系统掌握现代网页样式与布局
前端·css
前端技术官2 天前
一行 CSS 新特性干掉 20 行 JavaScript ?
css·滚动驱动动画·容器查询·:has()·anchor positioning
Beginner x_u3 天前
Tailwind CSS 速通:有 CSS 基础的实战入门
css·tailwindcss·工程化
WL_arm3 天前
Vibe Coding(氛围编程)入门
javascript·css·人工智能·html5
谙忆10244 天前
图片裁剪总是跑偏?用 object-fit、object-position 和真实像素把坐标对齐
javascript·css·图像识别
01_ice4 天前
前端学习css
前端·css·学习
zh_xuan5 天前
个人主页左侧菜单支持分组,以及菜单显示和隐藏
前端·javascript·css