[英]Make Bottom Div Scrollable when parent Div is over X Height
我試圖有一個固定高度為 350px 的容器 div。在那個 div 里面,有 2 個子 Div,兩者的高度都是可變的。
我現在的目標是,如果 2 個子 div 加在一起大於父 div,則底部子 div 將獲得一個滾動條。
現在的問題是,無論我嘗試什么,父 div 都會擴展 350 像素的最大高度。
這就是我現在的方式:
<div id="parent-left">
<div id="top">
Top-Content<br>
Top-Content<br>
Top-Content<br>
Top-Content<br>
Top-Content<br>
Top-Content
</div>
<div id="bottom">
Bottom-Content<br>Bottom-Content<br>Bottom-Content<br>Bottom-Content<br>
Bottom-Content<br>Bottom-Content<br>Bottom-Content<br>Bottom-Content<br>
Bottom-Content<br>Bottom-Content<br>Bottom-Content<br>Bottom-Content<br>
Bottom-Content<br>Bottom-Content<br>Bottom-Content<br>Bottom-Content<br>
Bottom-Content<br>Bottom-Content<br>Bottom-Content<br>Bottom-Content<br>
Bottom-Content<br>Bottom-Content<br>Bottom-Content<br>Bottom-Content<br>
Bottom-Content<br>Bottom-Content<br>Bottom-Content<br>Bottom-Content<br>
Bottom-Content<br>Bottom-Content<br>Bottom-Content<br>Bottom-Content<br>
</div>
</div>
<div id="parent-right">
Other Div with actual height of 350px
</div>
#parent-left {
height: 350px;
background: red;
width: 50%;
float: left;
}
#parent-right {
height: 350px;
background: red;
width: 50%;
float: right;
}
#top {
background:#5ae;
}
#bottom {
background:#ea5;
height:100%;
overflow-y: auto;
}
如您所見,Red Div(實際 350px 高度)不是相同的高度,因為 parent-left div 更大。
當我自己定義高度時,我知道這是可能的(例如: http : //jsfiddle.net/by96zof3/ ),但這會殺死 div 的可變高度。
所以我想要的是 #parent-left div 不超過 350px,但我也不必在里面定義任何高度。
我可以使用 JS(和 JQuery),但如果可能的話,我更喜歡沒有它的解決方案。
有人有一些想法嗎?
flex
是你的朋友,我的朋友。
#parent-left {
height: 350px;
background: red;
width: 50%;
float: left;
display: flex;
flex-direction: column;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.