我有一个元素,需要能够根据放入它的内容进行增长和缩小。它有多个嵌套的div,以适应分层元素。
我遇到的问题是当内容大于max-height时滚动它。
我相信这是因为所有父div都是位置:绝对。 如果我使溢出元素绝对,那么我得到的只是一个零空间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;
}
答案 0 :(得分:2)
#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;
}
&#13;
<div id="container">
<div id="border">
<div id="text">TEXT TO BE ENTERED VIA JS saaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa saaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa saaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa saaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa saaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa saaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa saaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa saaaaaaaaaaa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