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>

实现效果

相关推荐
拜无忧10 小时前
纯css,顺时针3d旋转基座(摩天轮效应)
前端·css
i_am_a_div_日积月累_15 小时前
css排除样式:not:has
前端·css
咬人喵喵16 小时前
网页开发的“三剑客”:HTML、CSS 和 JavaScript
javascript·css·html
BUG创建者17 小时前
thee.js完成线上展厅demo
开发语言·前端·javascript·css·html·css3·three.js
我有一棵树17 小时前
css 的回溯机制、CSS 层级过深的选择器会影响浏览器的性能
前端·css
光头程序员18 小时前
Vite 前端项目 - CSS变量智能提示
前端·css
晴殇i1 天前
CSS Grid 与 Flexbox:现代前端布局的双子星
前端·css
曹卫平dudu1 天前
一起学习TailWind Css
前端·css
加油乐2 天前
css及js实现正反面翻转
前端·javascript·css
踢球的打工仔2 天前
前端css(2)
前端·css