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>

实现效果

相关推荐
WebDesign_Mu4 小时前
为了庆祝2025英雄联盟全球总决赛开启,我用HTML+CSS+JS制作了LOL官方网站
javascript·css·html
Bellafu66610 小时前
selenium的css定位方式有哪些
css·selenium·tensorflow
我有一棵树11 小时前
前端开发中 SCSS 变量与 CSS 变量的区别与实践选择,—— 两种变量别混为一谈
前端·css·scss
im_AMBER12 小时前
CSS 01【基础语法学习】
前端·css·笔记·学习
DokiDoki之父12 小时前
前端速通—CSS篇
前端·css
尘世中一位迷途小书童13 小时前
🎨 SCSS 高级用法完全指南:从入门到精通
前端·css·开源
Giant10013 小时前
小白也能懂的响应式布局:从 0 到 1 学会适配所有设备
css
银安14 小时前
CSS排版布局篇(8):Grid 二维布局
前端·css
华仔啊16 小时前
Vue3 登录页还能这么丝滑?这个 hover 效果太惊艳了
前端·css·vue.js
牧杉-惊蛰1 天前
disable-devtool 网络安全 禁止打开控制台
前端·css·vue.js