前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >处理flex弹性,space-between,space-around 的最后一行

处理flex弹性,space-between,space-around 的最后一行

作者头像
拿我格子衫来
发布2022-01-24 15:55:08
1K0
发布2022-01-24 15:55:08
举报
文章被收录于专栏:TopFE

先看效果图

在这里插入图片描述
在这里插入图片描述

最后一行补位,补充多个元素, height: 1px;visibility: hidden

使用了最小宽度来保证每个元素在缩放时,能够以最小宽度正常显示。也有一个固定宽度为了避免数据少时,独占一行,显示难看。

解决上下行元素 多出的间隔 使用align-content: baseline;

核心代码

代码语言:javascript
复制
.item.h1 {
      height: 1px;
      visibility: hidden
 }
代码语言:javascript
复制
 <!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="author" content="http://www.softwhy.com/" />
    <title>scrollWidth和scrollHeight属性-蚂蚁部落</title>
    <style type="text/css">
        .container {
            width: 90%;
            border: 1px solid #ddd;
            display: flex;
            height: 600px;
            overflow: auto;
            justify-content: space-around;
            flex-wrap: wrap;
            align-content: baseline;
        }

        .container::after {
            /* content: ""; */
            /* flex: auto; */
            /* margin-right: 10px; */
        }

        .item {
            /* margin-top: 50px; */
            margin-right: 10px;
            padding: 0 10px;
            height: 50px;
            /* background-color: red; */
        }

        .item {
            flex: 1;
            border: 1px solid red;
            height: 100px;
            min-width: 240px;
            width: 300px;
            margin-right: 10px;
            margin-bottom: 20px;
        }

        .item.h1 {
            height: 1px;
            visibility: hidden
        }
    </style>
</head>

<body>

    <div class="container">
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="item h1"></div>
        <div class="item h1"></div>
        <div class="item h1"></div>
        <div class="item h1"></div>
        <div class="item h1"></div>
    </div>

</body>

</html>
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档