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>

实现效果

相关推荐
谅望者4 小时前
Flexbox vs Grid:先学哪一个?CSS 布局完全指南(附可视化示例)
前端·css·html·css3·css布局·css flexbox·css grid
listhi52010 小时前
CSS:现代Web设计的不同技术
前端·css
自由日记10 小时前
css属性使用手册
前端·css·html
znhy@12316 小时前
CSS3属性(三)
前端·css·css3
xiaoxiao无脸男1 天前
纯css:一个好玩的按钮边框动态动画
前端·css·css3
Fanfffff7201 天前
前端样式局部作用域:从Scoped到CSS Modules 的完整指南
前端·css
低保和光头哪个先来1 天前
如何实现弹窗的 双击关闭 & 拖动 & 图层优先级
前端·javascript·css·vue.js
DarkBule_2 天前
0成本get可信域名:dpdns.org公益域名获取全攻略
css·学习·html·github·html5
营赢盈英2 天前
How to detect if <html> tag has a class in child Angular component
前端·javascript·css·html·angular.js
!win !2 天前
从一个按钮实例入门CSS in JS之styled-components
css·react