css - 最小高度:如果父母只设置了最小高度而不是高度,则 100% 不起作用
问题描述
我有一个带有固定的父容器min-height
和一个带有min-height: 100%
. 但是,子容器不会填满父容器的整个高度。
它看起来像这样(Chrome 90):
.parent {
background-color: lightgreen;
min-height: 200px;
}
.child {
background-color: yellow;
min-height: 100%;
}
<div class='parent'>
<div class='child'>
child
</div>
</div>
但我希望这样:
奇怪的是,在设置height
而不是min-height
在父级上时,它可以工作:
.parent {
background-color: lightgreen;
height: 200px;
}
.child {
background-color: yellow;
min-height: 100%;
}
<div class='parent'>
<div class='child'>
child
</div>
</div>
有谁知道为什么?
解决方案
最简单的解决方法是添加height: 1px;
到.parent
. 它不影响min-height
,所以你很高兴。
.parent {
background-color: lightgreen;
min-height: 200px;
height: 1px;
}
.child {
background-color: yellow;
min-height: 100%;
}
<div class='parent'>
<div class='child'>
child
</div>
</div>
推荐阅读
- javascript - Laravel - Jquery,Ajax - 将 Nullable 数据作为数组插入数据库中
- google-cloud-platform - 谁支付 BigQuery 中跨多个用户的数据集的查询费用?
- mysql - 在 phpmyadmin 的存储过程中设置变量
- java - W/audio_hw_generic:没有为 HAL 泛洪 logcat 提供足够的数据?
- linux - Docker 不应该将新文件写入原始目录
- ubuntu - 安装 ros-kinetic-desktop-full 后找不到“rxtools”
- jquery - 点击展开 JSON 数据
- c# - 等待另一个任务的异步任务
- javascript - 纯 html+css+js 中的 CSS 设置与 Node.JS 中的不同
- r - 在频率表中搜索特定单词