html - 使用 flex-wrap 移动到下一行时保持 div 宽度的 Flex 盒设计
问题描述
我有这个演示代码5
,其中,的宽度6
与7
上面的 div 不同。
一种简单的方法是添加隐藏的空 div。但是,有没有更好的方法?
.parent-wrapper {
height:100%;
width: 400px;
border: 1px solid black;
}
.parent {
display: flex;
flex-wrap:wrap;
}
.child {
background:blue;
flex: 1 0 21%;
height:100px;
margin: 5px;
}
<body>
<div class="parent-wrapper">
<div class="parent">
<div class="child">1</div>
<div class="child">2</div>
<div class="child">3</div>
<div class="child">4</div>
<div class="child">5</div>
<div class="child">6</div>
<div class="child">7</div>
</div>
</div>
</body>
最后,我想使用一些动态值来渲染它,所以我认为 CSS 方式会比添加空 div 更好
解决方案
不要求它成长怎么样,演示在这里
.child {
background:blue;
flex: 0 0 21%; //<-- note 0 here
height:100px;
margin: 5px;
}
推荐阅读
- python - python subprocess.Popen 冻结 tkinter 窗口
- android - 如何在 Play Store 上发布带有 SQLServer 数据库(Web 服务)的 Android 应用程序?
- gerrit - 如何将 gerrit 2.16 迁移到 gerrit 3.0 ?“--migrate-to-note-db”不是一个有效的选项
- pyspark - 使用pyspark从1开始按递增顺序添加行号列
- c++ - 函数必须只有一个参数
- delphi - 如何在不知道 Outlook 版本(2010、2013、2016 等)的情况下从服务应用程序登录
- pandas - 从 psycopg2 光标的 pandas 数据帧中删除编码“UTF8”:0x00 字符
- docker - 获取“您的意思是运行 dotnet SDK 命令吗?请从以下位置安装 dotnet SDK”
- php - 带有 Composer 的 PHP 结构不起作用
- python - 转义单引号时遇到问题