CSS滚动百分比div
问题描述:
我有一个div,我想有一个垂直滚动条。CSS滚动百分比div
到目前为止,我已经使用了下面的CSS,工作正常:
.mywrapper {
max-height: 300px;
overflow: auto;
}
不过,我想div来承担尽可能多的垂直空间的页面上尽可能。由于这是页面上的最后一个div,因此如果可能,我希望它一直延伸到底部。
答
你不能这样做,自然。身体只与其包含的内容一样高。
但是,一个简单的速战速决将加入给你的CSS:
html,body { height: 100%; margin: 0; padding: 0; }
至于延长,我已经把一个快速脚本(使用jQuery)出现做你正在寻找。
请参阅:http://jsfiddle.net/UB7uT/(点击播放)
代码:
CSS:
html,body { height: 100%; margin: 0; padding: 0; overflow: hidden; }
.mywrapper {
overflow: auto;
max-height: 100%;
}
的JavaScript:
function my_initialize_footer_box_absolute_height_scroller(selector) {
var box = $(selector);
var boxPosition = box.position();
var boxTop = boxPosition.top;
var boxHeight = box.height();
var boxNewHeight = (+boxHeight) - (+boxTop);
box.css('height', boxNewHeight+'px');
}
$(function() {
my_initialize_footer_box_absolute_height_scroller('.mywrapper');
});
HTML:
<p>some content here first.</p>
<p>some content here first.</p>
<p>some content here first.</p>
<p>some content here first.</p>
<hr>
<div class="mywrapper">
foo<br>foo<br>foo<br>foo<br>foo<br>foo<br>foo<br>foo<br>
</div>
需要链接到一个例子,看得更清楚。 – circusdei 2012-02-08 21:04:45
你正在使用什么DOCTYPE? '尽可能多的空间',你明确告诉它不要超过300px的高度 – Cheery 2012-02-08 21:07:04
我意识到目前它只会占用300px。我想使用从div的开头到页面底部的所有内容的100%代替。 – JonoB 2012-02-08 21:12:22