2010-03-21 54 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