css - Flexbox - 孩子不是 100% 的高度
问题描述
我有一个像这样的基本弹性布局
.container {
display:flex;
width:100%;
justify-content: space-between;
height:100%;
}
.left {
width: calc(61.8034% - ( 0.38196600790794 * 20px ) );
}
.right {
width: calc(38.1966% - ( 0.61803399209206 * 20px ) );
}
.left, .right {
height:100%;
height:100%;
}
.image_container {
background:red;
height:100%;
}
.image_container img {
display:none;
}
.image_16x9_container{
background:green;
display: block;
height: 0;
padding-bottom: 56.25%;
overflow: hidden;
}
<div class="container">
<div class="left">
<div class="image_container">
This is some example text
</div>
</div>
<div class="right">
<div class="image_16x9_container">
<img src="https://picsum.photos/500/500">
</div>
</div>
</div>
我无法弄清楚为什么左侧 div 不是 100% 高度,我认为让父 div flex 会自动解决这个问题。
我哪里错了?
解决方案
你是对的,但你不必height:100%
在弹性项目上进行设置,因为它不会工作,并且会破坏默认情况下使元素 100% 高度的默认拉伸行为:
.container {
display: flex;
width: 100%;
justify-content: space-between;
}
.left {
width: calc(61.8034% - ( 0.38196600790794 * 20px));
}
.right {
width: calc(38.1966% - ( 0.61803399209206 * 20px));
}
.image_container {
background: red;
height: 100%;
}
.image_container img {
display: none;
}
.image_16x9_container {
background: green;
display: block;
height: 0;
padding-bottom: 56.25%;
overflow: hidden;
}
<div class="container">
<div class="left">
<div class="image_container">
This is some example text
</div>
</div>
<div class="right">
<div class="image_16x9_container">
<img src="https://picsum.photos/500/500">
</div>
</div>
</div>
推荐阅读
- python - 音频文件无法读取为 PCM WAV、AIFF/AIFF-C 或 Native FLAC;检查文件是否损坏或其他格式
- json - 由加特林的 JSON Feeder 生成的 JSON 字符串中的 Vector()
- python - 如何在 Flask-SocketIO 中打印 HTML 字符而不进行迭代(追加)?
- laravel - Laravel:从数据库设置配置文件的值
- stata - 如何在Stata中的广义估计方程后检查自相关?
- python - 制作和打印包含输入值的字典的代码输出不完整的字典;为什么?
- postgresql - Ecto - 在单个查询中返回按日期分组的时间戳记录
- cloudify - 如何在不使用 cloudify 更改 OS 中子网 UUID 的情况下使用 execute_operation 更新子网名称
- docker - 在 Docker 上运行时出现 Redis 错误“无法打开 RDB 文件 dump.rdb”
- awk - sed:-e 表达式#1,字符 2:命令后的额外字符