2010-03-21 17 views
1

我不知道如何設置一個iframe的屬性,它位於頂部300px的位置,但應該總是觸及底部!jquery(或CSS)將iframe自動調整爲底部?

所以目前我已經把iframe的高度設置爲500px。當我調整瀏覽器窗口大小時,高度應該動態改變。 iframe應該從頂部開始300px,並且應該始終到達底部。

我不是一個css專家。 任何想法我必須做什麼?

#frame { 
overflow:hidden; 
border:none; 
width:100%; 
height:500px; 
margin-top:300px; 
} 

回答

1
html, body { /* Allow the #wrapper div to stretch 100% in both directions */ 
    height: 100%; 
    width: 100%; 
    margin: 0; 
} 
#wrapper { /* necessary because it for some reason doesn't work with the iframe */ 
    position: absolute; 
    top: 300px; 
    bottom: 0; 
    left: 0; 
    right: 0; 
} 
#frame { 
    width: 100%; 
    height: 100%; 
    border: 0; 
} 

<div id="wrapper"> 
    <iframe id="frame" src="http://www.google.com" /> 
</div> 
+0

謝謝你的解決方案,現在我知道,我的錯了:) 我檢查了它,它的工作原理: http://jsbin.com/eruyo/2/edit – Thinker 2010-03-22 09:18:16

0

您可以像使用'margin-top'一樣使用'margin-bottom'。最簡單的CSS方式,但我不確定,如果這適用於每個瀏覽器。

+0

它不適合我。在這種情況下我必須設置一個高度嗎?如果我只設置了margin-top和margin-bottom:0,它不起作用。該iframe獲得像100px的高度! – matt 2010-03-21 10:18:06

+0

對不起,底部似乎沒有工作,當頂部使用:( 我認爲你需要使用javascript – Thinker 2010-03-21 14:26:34