這裏是jQuery的溶液與
#contactlist
CSS高度調節:
#wrapper { width: 200px; height: 400px; border: 4px solid black; }
#header { height: 50px; border: 2px solid red; }
#contactlist { overflow: scroll; height: 344px; border: 2px solid blue; }
(僅修改的聯繫人列表的高度)
的jQuery碼(置換的一個) :
h = $('#wrapper').height() ;
windowh = $(window).height();
$(window).resize(function(){
var newh = h + ($(this).height() - windowh);
$('#wrapper').height(newh);
$("#contactlist").height(newh-56); //56 = 50 for header + 6 for border
});
使用此代碼,與窗口大小調整同時,您可以通過滾動來增加或減少#wrapper
和#contactlist
的高度。
小提琴演示:http://jsfiddle.net/ajp9h/
哦,是的,正好。 – johnny 2012-04-17 17:06:46
我想我不明白的是,它似乎希望容器(#wrapper)具有固定的高度(根據您的示例),但希望內容根據瀏覽器大小更改大小? – 2012-04-17 17:08:15
靈活的是#wrapper的大小。它的身高是身體的80%(我無法在jsfiddle中重新創建它)。當我現在調整瀏覽器的大小時,#wrapper的高度也會改變,因此#contactlist也應該縮小。 – johnny 2012-04-17 17:15:27