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>

实现效果

相关推荐
燕落南枝19 小时前
CSS 表单选择器与伪元素选择器详解
前端·css
狮子座的男孩1 天前
html+css基础:25、3D变换(3D空间与景深/透视点的位置/位移/旋转/缩放/多重变换/背部可见性)
css·经验分享·html·旋转·透视点·缩放/位移·3d变换/空间与景深
思码梁田2 天前
CSS 浏览器厂商前缀:从「写 5 遍」到现代自动化兼容
前端·css·css3·border-radius·1024程序员节·box-shadow·厂商前缀
feixing_fx3 天前
CSS Grid 入门:二维布局时代的降维打击
前端·css·前端框架·css3
2603_965896623 天前
CSS BEM 命名规范|组件化样式分层权威指南
前端·javascript·css
进击的明明3 天前
前端开发中的 BEM 国际命名规范:让 CSS 不再"打架"
前端·css·html
燕落南枝3 天前
CSS 分组选择器与链接伪类选择器详解
前端·css
溪语流沙3 天前
【每天一个CSS | Day33】聚焦即弹出的命令面板
前端·css·html5·组件·每日一练
燕落南枝3 天前
CSS 用户行为伪类::hover 与 :focus 详解
前端·css
钱栈up4 天前
前端改了三页、后端也动了,用户说「完全没变化」——我在 116 库上找到的三个真凶
css·数据库