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>

实现效果

相关推荐
be or not to be9 小时前
CSS 背景(background)系列属性
前端·css·css3
冴羽9 小时前
CSS 新特性!瀑布流布局的终极解决方案
前端·javascript·css
牛奶皮子11 小时前
合并 CSS 文件可以减少 HTTP 请求数,因为每个请求都会带来额外的网络开销
css·网络·http
幻影星空VR元宇宙17 小时前
9D裸眼轨道影院投资多少钱与5D动感影院设备的市场潜力分析
css·百慕大冒险·幻影星空
proud121219 小时前
使用thymeleaf生成PDF方案
javascript·css·pdf
霍理迪21 小时前
CSS——背景样式以及雪碧图、渐变
前端·css
wordbaby1 天前
Flexbox 布局中的滚动失效问题:为什么需要 `min-h-0`?
前端·css
前端小黑屋2 天前
查看 Base64 编码的字体包对应的字符集
前端·css·字体
hqwest2 天前
码上通QT实战04--主窗体布局
开发语言·css·qt·布局·widget·layout·label
狗哥哥2 天前
企业级 Vue3 + Element Plus 主题定制架构:从“能用”到“好用”的进阶之路
前端·css·架构