纯flex布局来写瀑布流

项目场景:

提示:这里简述项目相关背景:

这里使用了flex 布局 来形成瀑布流


解决方案:

提示:这里填写该问题的具体解决方案:

1:方法1

css 复制代码
<div
    style="
    max-width: 1500px;
    min-width: 300px;
    margin-right: 60px;
    height: 500px;
    padding: 10px;
    border: 1px solid #ccc;"
>
    <div style="display: flex; flex-wrap: wrap;width:100%;height:100%">
        /*flex 根据需要调整列宽和间距 0不放大 1会缩小 
        设置占据的主轴空间 减去两边margin 内部的margin不用 因为在100% 的宽度里
        比如 下面的 margin:0 15px; 那么就应该 flex: 0 1 calc(33.333% - 30px)*/
        <div
            style="
            flex: 0 1 calc(33.333% - 20px);
            margin: 0 10px;
            margin-bottom: 10px; /* 列间距 */
            box-sizing: border-box;
            border: 1px solid #ddd;"
            v-for="i in 20"
          >
            {{ i }}
        </div>
    </div>
</div>

为20

为10

2:方法2

需要设定宽高,不然宽高要靠内容撑起来

css 复制代码
<div
        style="
          max-width: 1500px;
          min-width: 300px;
          margin-right: 60px;
          height: 500px;
          padding: 10px;
          border: 1px solid #ccc;
        "
      >
        <div style="display: flex; flex-wrap: wrap; align-content: center">
          <div
            class=""
            style="
              margin: 0 10px;
              margin-bottom: 10px; /* 列间距 */
              box-sizing: border-box;
              border: 1px solid #ddd;
              width: 100px;
              height: 50px;
            "
            v-for="i in 20"
          >
            {{ i }}
          </div>
        </div>
</div>

布局样式

相关推荐
程序员老赵3 分钟前
Docker 部署青龙面板:轻松搭建定时任务管理平台
前端·docker·开源
Swot5 分钟前
Asciidoctor 公式数字下标错位问题:原因分析与解决方案
前端
Swot5 分钟前
leo-editor 中将 Markdown 内容转成 asciidoc 格式
前端
狒狒AI17 分钟前
Remotion / GSAP+Three / HyperFrames / Skia 四栈实测:代码渲染知识视频的选栈方法(附开源技能)
前端·人工智能·aigc
修炼的dance18 分钟前
浏览器里导出H.265,8.5秒和55.5秒差在硬件
前端
补码缩写19 分钟前
WebCodecs选编码器,探测之后还要验解码和播放
前端
大文说跨境20 分钟前
亚马逊多账号管理浏览器怎么选?云登/紫鸟/AdsPower 对比
java·前端·自动化
hunter_07623 分钟前
iOS 首页复杂嵌套滚动技术方案:头部固定 + 网格滚动 + Tab 吸顶 + 每 Tab 独立下拉刷新
前端
CoderYanger35 分钟前
Java EE 进阶:4.Spring Web MVC 入门(第一弹)
java·开发语言·前端·spring·面试·java-ee·mvc
用户27886072856736 分钟前
fallback 会盖掉平台提示词:system、空数组和 systemAppend 的差别
前端·后端