gpt4 book ai didi

css - 最大高度,溢出 :scroll and position

转载 作者:太空宇宙 更新时间:2023-11-04 03:45:20 24 4
gpt4 key购买 nike

我有一个元素需要能够根据放入其中的内容进行增长和收缩。它有多个嵌套的 div 以适应分层元素。

我遇到的问题是当内容大于最大高度时让它滚动。

我相信这是由于所有父 div 都是 position: absolute。如果我使溢出元素成为绝对元素,那么我得到的只是一个空空间 IE 周围的边框;一个点。即使我给它设置了宽度和高度,也会发生这种情况。如果我将它设置为相对的,那么它会正确显示所有内容,但溢出元素的内容会超过包含元素的底部,即使它设置为溢出:滚动或自动。

所以我需要一种方法让父元素识别溢出的大小并扩展以包含它们,同时允许溢出元素在超过特定大小后滚动。

html代码

<div id="container">
<div id="border">
<div id="text">
TEXT TO BE ENTERED VIA JS
</div>
</div>
</div>

目前的CSS代码

#container
{
position: fixed;
top: 0px;
right: 0px;
bottom: 0px;
width: 50%;
padding: 0;
margin: 0;
}

#border
{
position: absolute;
top: 2.5%;
border: 2px solid black;
border-radius: 20px;
background-color: LightGoldenRodYellow;
padding: 0;
margin: 0% 5%;
max-height: 95%;
overflow: hidden;
}

#text // this is the part I am having trouble with.
{
position: relative;
max-height:80%;
overflow-y: scroll;
overflow-x: hidden;
}

最佳答案

#container {
position: fixed;
top: 0px;
right: 0px;
bottom: 0px;
width: 50%;
padding: 0;
margin: 0;
}
#border {
position: absolute;
top: 2.5%;
border: 2px solid black;
border-radius: 20px;
background-color: lightgoldenrodyellow;
padding: 0;
margin: 0% 5%;
max-height: 95%;
width: 200px;
overflow: hidden;
}

#text {
overflow-y: scroll;
overflow-x: hidden;
max-height: 200px;
}
<div id="container">
<div id="border">
<div id="text">TEXT TO BE ENTERED VIA JS saaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa saaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa saaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa saaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa saaaaaaaaaaaaaaaaaaaaaaaa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aaaaaaaa saaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa saaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa saaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa saaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa saaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa saaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa saaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa saaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa saaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa saaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa saaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
</div>
</div>

给你。

关于css - 最大高度,溢出 :scroll and position,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24227053/

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