gpt4 book ai didi

css - 将 div 高度设置为 englobing div 高度

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

我有一个包含两个对齐的 div 的 div。不幸的是,右侧的 div 没有从其背景颜色可见的正确高度。我怎样才能确保它会将其高度调整为 englobing div 的高度?

HTML:

<div id="engl">
<div id="lleft">Some text text
text text text text text text
text text text text text text
</div>
<div id="rright">Other text</div>
</div>

CSS:

#engl {
background-color: red;
width: 200px;
height: auto;
overflow: auto;
}

#lleft {
background-color: yellow;
width: 140px;
padding: 10px;
float: left;
}

#rright {
background-color: green;
width: 40px;
float: left;
height: inherited;
}

JsFiddle:http://jsfiddle.net/9bLLN/1/

最佳答案

你可以使用定位来做到这一点:

#engl {
background-color: red;
width: 200px;
height: auto;
overflow: auto;
position:relative; /*NEW*/
}
#lleft {
background-color: yellow;
width: 140px;
padding: 10px;
float: left;
}
#rright {
background-color: green;
width: 40px;
float: left;
height: inherited;
position: absolute; /*NEW*/
top:0; /*NEW*/
bottom:0; /*NEW*/
right:0; /*NEW*/
}

jsFiddle example

关于css - 将 div 高度设置为 englobing div 高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20588341/

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