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>

实现效果

相关推荐
啾咪orJIUMI21 小时前
Vue 3 + SCSS 实现全屏系统门户:五栏展开与灯光联动
css
程序员大阳21 小时前
HTML+CSS+JS对话式实战(1)-开篇:认识我们要做的社团活动发布平台
javascript·css·html·实战·系统·平台·社团活动发布
志尊宝2 天前
AI原生前端开发(043):AI辅助的样式生成(Tailwind CSS)
前端·css·ai-native
java1234_小锋3 天前
【技术专题】CSS3 网页技术 - CSS3 布局进阶
前端·css·css3
java1234_小锋3 天前
【技术专题】CSS3 网页技术 - CSS3 视觉增强
前端·css·css3
晓得迷路了3 天前
栗子前端技术周刊第 152 期 - Rspack 2.3、TypeScript 7.1 Beta、Bun 1.4.4...
前端·javascript·css
普通人63 天前
CSS-box-sizing-使用指南
开发语言·前端·css·1024程序员节
前端架构师-老李3 天前
HTML与CSS基础第七课—HTML 中的a标签(跳转链接)
前端·css·html
溪语流沙4 天前
【每天一个CSS | Day41】开关三连:一套状态机,三种视觉翻译
前端·css·html5·每日一练·按钮
变与不变8064 天前
css定位布局精讲
前端·css