【问题标题】:Jquery (or CSS) autoresize iframe to the bottom?Jquery(或CSS)将iframe自动调整到底部?
【发布时间】:2010-03-21 09:34:06
【问题描述】:

我不知道如何为距顶部 300 像素的 iframe 设置属性,但应该始终到达底部!

所以目前我已将 iframe 的高度设置为 500 像素。当我调整浏览器窗口的大小时,高度应该动态变化。 iframe 应该从顶部开始 300 像素,并且应该始终到达底部。

我不是一个 css 专家。 知道我要做什么吗?

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

【问题讨论】:

    标签: jquery css iframe


    【解决方案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>
    

    【讨论】:

    • 感谢您的解决方案,现在我知道了,我的问题出在哪里 :) 我检查了它,它有效:jsbin.com/eruyo/2/edit
    【解决方案2】:

    您可以像使用“margin-top”一样使用“margin-bottom”。最简单的 CSS 方式,但我不确定这是否适用于所有浏览器。

    【讨论】:

    • 它对我不起作用。在那种情况下我必须设置一个高度吗?如果我只设置 margin-top 和 margin-bottom:0 它不起作用。 iframe 的高度约为 100 像素!
    • 对不起,底部似乎不起作用,当使用顶部时:(我认为你需要使用javascript
    猜你喜欢
    • 1970-01-01
    • 2010-12-25
    • 2013-11-21
    • 1970-01-01
    • 2012-01-21
    • 1970-01-01
    • 2011-12-15
    • 1970-01-01
    • 2011-12-27
    相关资源
    最近更新 更多