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>

实现效果

相关推荐
不考研当牛马15 小时前
HTML CSS 新手大全初学者必看 (含有部分 JavaScript)
javascript·css·html
暗不需求16 小时前
告别“class 命名地狱”:从面向对象 CSS 到原子 CSS(Tailwind) 的思维跃迁
前端·css·react.js
极客小俊18 小时前
【从零到一】用HTML5+CSS+JavaScript实现一个属于自己的mp3免费音乐播放器 (4) JS交互功能(音乐进度条)
javascript·css·html5·前端开发·免费教程·代码案例·手搓音乐播放器
何何____18 小时前
css变换语法介绍及案例展示
前端·css
gCode Teacher 格码致知21 小时前
Javascript提高:点击飘忽不定的气球,气球爆炸并增加分数-由Deepseek产生
javascript·css·css3
用户0595401744621 小时前
Playwright 多标签页 IndexedDB 同步测试踩坑实录:折磨我6小时的浏览器沙箱陷阱
前端·css
Raytheon_code1 天前
从零到一:我用微信小程序做了一款串珠DIY定制工具
css·微信小程序·html5·ai编程
摇滚侠2 天前
11 空间转换 前端 Web 开发 HTML5 + CSS3 + 移动 web 视频教程,前端web入门首选黑马程序员
前端·css·html·css3·html5
小李子呢02112 天前
前端八股CSS---CSS布局
css·html·css3