html - 为什么我的子 div 不能滚动并在列中居中?
问题描述
我正在努力使我的.centerIt
div 垂直居中,并.div1
在我将更多.centerIt
div 添加到列中后保持可滚动。
在我添加更多的.centerIt
div 之后,它们必须保持它们height: 20px
而不是挤压。
.container {
display: flex;
background: red;
width: 300px;
height: 300px;
}
.div1 {
background: yellow;
height: 90%;
width: 27%;
margin: 5px;
overflow-y: scroll;
}
.div2 {
background: blue;
height: 90%;
width: 74%;
margin: 5px;
}
.centerIt {
background: green;
width: 100%;
border: solid 1px black;
height: 20px;
color: green;
}
<div class="container">
<div class="div1">
<div class="centerIt"></div>
<div class="centerIt"></div>
<div class="centerIt"></div>
<div class="centerIt"></div>
<div class="centerIt"></div>
<div class="centerIt"></div>
<div class="centerIt"></div>
<div class="centerIt"></div>
</div>
<div class="div2"></div>
</div>
解决方案
只需尝试添加min-height: 20px
到.centerIt
而不是高度和
display: flex;
flex-direction: column;
justify-content: center;
要.div1
款式,应该做的。
推荐阅读
- google-api - Kubernetes 中的符号链接秘密
- powershell - 使用 powershell 将所有打印机复制到新机器
- intellij-idea - 如何在 IntelliJ 中将文件添加到版本控制?
- python - 在对 groupby 执行求和后保留输出中的列
- xml - 第 4 行第 5 列的错误:文档末尾的额外内容
- arduino - Arduino UNO GSM
- java - 如何在不知道 Java 枚举类型的情况下使用反射比较多个枚举?
- java - 如何使用 Log4j 注册额外的 PropertySource?
- windows - Windows - 批量符号链接文件和文件夹递归
- php - Codeigniter 没有更新我的数据