gpt4 book ai didi

css - 如何使用绝对定位的 child 自动延长父亲的高度?

转载 作者:行者123 更新时间:2023-11-28 14:56:47 24 4
gpt4 key购买 nike

<head>
<style type = "text/css">
body{
text-align:center;
}

#container{
position:relative;
width:600px;
height:auto;
border:1px solid #ccbbaa;
}

#box{
position:absolute;
width:300px;
left:2px;
border:1px solid #ccbbaa;
}


</style>
</head>
<div id = "container">

<div id = "box">
<p>
message .....
</p>
<p>
message .....
</p>
</div>
</div>

问题是如何使用不固定的高度使容器和盒子的高度保持一致。

谢谢。

最佳答案

你会用javascript吗?这是我使用 jQuery 的方式:

$("#box").resize(function() {
$("#container").width($(this).width()).height($(this).height());
});

关于css - 如何使用绝对定位的 child 自动延长父亲的高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3518059/

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