html - 如何使用 CSS 隐藏 flex 列中的部分行?
问题描述
这在标题中很难解释。我有一个 div,它显示列的 flex 和 flex-direction,其中有很多行:
<div class="flex column">
<div class="row">Content of row</div>
<div class="row">Content of row</div>
<div class="row">Content of row</div>
<div class="row">Content of row</div>
<div class="row">Content of row</div>
//etc
</div>
每行都说 20px 高,并且容器隐藏了溢出。除非容器的高度是 20 的倍数,否则会留下部分可见的行。
我想要完成的是让 CSS 自动使行高足够高到最后一个半可见的行不再可见,并且以 px 为单位的新行高完全划分为父容器的高度。
这可以用纯 CSS 完成吗?
我可以接受的另一个选项是 CSS 自动隐藏现在部分可见的最后一行
解决方案
您可以依靠 wrap 功能,您的元素将自动移动到没人能看到的另一列。
调整以下示例的大小并查看:
.flex-column {
display:flex;
flex-direction:column;
flex-wrap:wrap; /* this is important */
height:200px;
overflow:hidden; /* this one too */
resize:vertical;
border:1px solid red;
}
.flex-column *{
height:25px;
flex-shrink:0;
border:2px solid green;
width:100%; /* and especially this one */
box-sizing:border-box;
}
<div class="flex-column">
<div class="row">Content of row</div>
<div class="row">Content of row</div>
<div class="row">Content of row</div>
<div class="row">Content of row</div>
<div class="row">Content of row</div>
</div>
推荐阅读
- windows - Windows 证书颁发机构申请表提交失败
- swift - 在注册用户时如何提供安全性?(例如:每个用户名必须不同,电子邮件必须有效等)
- java - 为什么在使用 CrudRepository spring-data-dynamodb 的 findBy 方法时出现 NullPointerException?
- mysql - 从今天起无法通过 XAMPP 连接到本地 MY SQL 数据库 (mysqli_real_connect(): (HY000/2002))
- git - 如何让 VS Code 的 Commit UI 在提交消息中支持 `#`?
- html - div内的可滚动div
- jquery - wordpress 中带有 ajax 的 slick-slider 过滤器幻灯片
- vb.net - 在数据库中的 PictureBox 中显示图像
- ansible - ansible:如果变量未定义,则使用默认值
- ruby-on-rails - 获取 Rails Activerecord 以使用数据库的外部 API id