我有一个绝对div卡在相对div的底部。我想要做的就是让内部div可滚动(向上),只要它的大小比外部div大。设置为底部时可以滚动内容:0;
但这并未发生。该div不会滚动!这里的小提琴:https://jsfiddle.net/xggjmjqc/
HTML:
<div class="mobile1">
<div class="bottom1">
</div>
</div>
<br><br>
<!-- when inner gets bigger than outer: -->
<div class="mobile2">
<div class="bottom2">
</div>
</div>
CSS:
.mobile1{
height:400px;
width: 300px;
background-color: red;
position: relative
}
.bottom1{
height:100px;
width: 300px;
position: absolute;
bottom: 0;
background-color: blue;
}
/* when inner gets bigger than outer: */
.mobile2{
height:400px;
width: 300px;
background-color: red;
position: relative;
overflow-y: scroll;
}
.bottom2{
height:500px;
width: 300px;
position: absolute;
bottom: 0;
background-color: blue;
}
使内部位置相对 – Daniel
如[此](https://jsfiddle.net/ xggjmjqc/2 /)? –
不能是相对的,因为这样它就不会粘在底部,以防它比外部(第一种情况)小。内部div的内容是一个变量,因此有时候可能会更小,有时可能更大。 – jonhz