我有兩個跨度div圍繞我的內容。我想讓他們填滿身高。 height: 100%;
在沒有需要滾動的情況下可以正常工作,但是一旦頁面足夠長以至於用戶需要滾動跨度時纔會出現第一個高度,然後不填充整個高度。有任何想法嗎? jsfiddle:http://jsfiddle.net/2fvcF/4/由於某些原因甚至沒有顯示跨度。使跨度填充高度 - 即使滾動時
1
A
回答
1
浮動元素不屬於主流。 你必須使用像this
0
function set_properties() {
$('#left').css('height', function() {
return $('#contentArea').innerHeight() + "px";
});
$('#right').css('height', function() {
return $('#contentArea').innerHeight() + "px";
});
}
$(document).ready(function() {
$(window).scroll(set_properties);
$(window).resize(set_properties);
set_properties();
});
或者改變一點點的CSS沒有必要使用JavaScript/jQuery的 您顯示的DIV爲表/細胞。
#contentArea {
width: 800px;
display: table;
color: #CCC;
margin-top: 0px;
background-color: #000;
margin-right: auto;
margin-bottom: 0px;
margin-left: auto;
border-right-width: 1px;
border-left-width: 1px;
border-right-style: solid;
border-left-style: solid;
border-right-color: #999;
border-left-color: #999;
height: 100%;
border-top-style: none;
border-bottom-style: none;
}
#contentArea #tc1,
#contentArea #tc3 {
display: table-cell;
width: 100px;
background-color: #F00;
}
<div id="contentArea">
<div id="tc1"> </div>
<div id="tc2">
<div class="header"> ... </div>
<div class="ui-widget" style="margin: 0px;"> ... </div>
<div class="main"> ... </div>
</div>
<div id="tc3"> </div>
</div>
+0
我只是在'
你能用jQuery嗎? – Gustonez
@Gustonez是的,只要它不會出現問題,並且可以與IE和其他惡意瀏覽器一起使用。在過去,我相信我看到的jQuery解決方案總是很糟糕。 – michaellindahl