您好我在找這個高度:Dynamically adjust an iframe's height但爲了能這樣做是爲了一個div,我有迄今如下:動態調整格
#NewsBlock {
height: 222px;
overflow-x: auto;
padding: 5px;
}
<div class="boxFive">
<h3 class="tab">Latest News</h3>
<script type="text/javascript">
function resizeIframe() {
var height = document.documentElement.clientHeight;
height -= document.getElementById('NewsBlock').offsetTop;
height -= 20; /* whatever you set your body bottom margin/padding to be */
document.getElementById('NewsBlock').style.height = height +"px";
};
document.getElementById('NewsBlock').onload = resizeIframe;
window.onresize = resizeIframe;
</script>
<div id="NewsBlock">
<div class="ShortNews">
<a href="" class="NewsLink"></a>
<p>title for news article<a href="#" title="Click to read more">more...</a></p>
</div>
<div class="ShortNews">
<a href="" class="NewsLink"></a>
<p>title for news article<a href="#" title="Click to read more">more...</a></p>
</div>
<div class="ShortNews">
<a href="" class="NewsLink"></a>
<p>title for news article<a href="#" title="Click to read more">more...</a></p>
</div>
<div class="ShortNews">
<a href="" class="NewsLink"></a>
<p>title for news article<a href="#" title="Click to read more">more...</a></p>
</div>
<div class="ShortNews">
<a href="" class="NewsLink"></a>
<p>title for news article<a href="#" title="Click to read more">more...</a></p>
</div>
<div class="ShortNews">
<a href="" class="NewsLink"></a>
<p>title for news article<a href="#" title="Click to read more">more...</a></p>
</div>
<div class="ShortNews">
<a href="" class="NewsLink"></a>
<p>title for news article<a href="#" title="Click to read more">more...</a></p>
</div>
<div class="ShortNews">
<a href="" class="NewsLink"></a>
<p>title for news article<a href="#" title="Click to read more">more...</a></p>
</div>
<div class="ShortNews">
<a href="" class="NewsLink"></a>
<p>title for news article<a href="#" title="Click to read more">more...</a></p>
</div>
</div>
</div>
,但似乎並不奏效,我錯過了什麼嗎?
我添加了CSS更改,並將js放在NewsBlock div後面但沒有更改,當我在http://jsfiddle.net/BWC27/上執行它時,它沒有按計劃工作,它的支持是相同的大小作爲內容文本分區的權利,所以他們都在同一個地方完成。我錯過了什麼嗎? –