gpt4 book ai didi

css - Flexbox - child 高度不是 100%

转载 作者:太空宇宙 更新时间:2023-11-04 01:07:06 25 4
gpt4 key购买 nike

我有一个像这样的基本 flex 布局

.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 会自动处理这个问题。

我哪里错了?

最佳答案

你是对的,但你不必在 flex 元素上设置 height:100% because it won't work并将打破默认使元素 100% 高度的默认拉伸(stretch)行为:

.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>

关于css - Flexbox - child 高度不是 100%,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51921213/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com