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>

实现效果

相关推荐
走粥2 天前
clsx和twMerge解决CSS类名冲突问题
前端·css
吠品2 天前
CSS图片居中:Flexbox、Grid与Transform的完整指南
前端·css
天若有情6732 天前
Canvas生成艺术|意外诞生的混沌风暴(附完整源码+GitHub部署)
前端·css·html·github·canvas·网页
阿珊和她的猫2 天前
React 中 CSS 书写方式全解析
前端·css·react.js
打瞌睡的朱尤2 天前
CSS复习
前端·css
我是伪码农2 天前
JS考核复写
前端·javascript·css
lightqjx2 天前
【前端】前端学习二之CSS
前端·css·学习·html
我命由我123453 天前
浏览器的 JS 模块化支持观察记录
开发语言·前端·javascript·css·html·ecmascript·html5
啥都不懂的小小白3 天前
前端CSS入门详解
前端·css
林恒smileZAZ3 天前
前端大屏适配方案:rem、vw/vh、scale 到底选哪个?
开发语言·前端·css·css3