[英]Scrollable div with Variable Height
我希望我的側邊欄具有可滾動的div。 但是它不能有固定的高度。 如何在不設置固定高度的情況下使其可滾動?
我嘗試過此方法,但無法正常工作。
.sidebar {width:300px; padding:10px; background:#efefef;height:100%; position:fixed}
.scroll-widget {overflow-y: scroll;padding:10px;margin:10px; background:#fffeee; height:inherit}
-
<div class=sidebar>
...
<div class=scroll-widget>
...
</div>
</div>
演示 : http : //jsfiddle.net/YK47P
jQuery替代對我也很好。 但是我是一個初學者,所以請客氣
我以某種方式能夠使用jQuery並從這里獲得幫助。
$(function () { // window load
$(window).resize(function () {
var sidebarH = $('.sidebar').height();
var scrollH = $('.top').height();
$('.scroll-widget').height(sidebarH - scrollH);
}).resize();
});
演示 : http : //jsfiddle.net/YK47P/40/
您只需要添加overflow: scroll
到側邊欄:
.sidebar {
width:300px;
padding:10px;
background:#efefef;
height:100%;
position:fixed;
overflow: scroll;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.