具有css固定位置的iframe:可能吗? [英] iframe with a css fixed position : possible?

查看:480
本文介绍了具有css固定位置的iframe:可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在外部网站上添加一些广告,为此,我使用iframe:

I would like to add some ads on an external website, to do so, I use iframe :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body style="background:#ddd">
<center>My ad</center>
<iframe src="http://www.google.com" style="position:fixed; top:50px; left:0; width: 100%; bottom: 0; border: 0 ">
<p>Your browser does not support iframes.</p>
</iframe>
</body>
</html>

iframe位于正确位置,但'bottom:0'不起作用:为什么?
我希望iFrame跟随窗口大小调整:如何继续?

The iframe is at the right position, but the 'bottom: 0' does not work : why ? I would like the iFrame to follow the window resizing : how to proceed ?

推荐答案

我知道这是一点点很晚,但我通过谷歌发现了这个问题,无疑其他人也会这样。如果你想以固定div的位置来固定iframe的位置,你可以将它包装在一个固定的位置div中并使它的大小为100%。

I know this is a little late, but I found this question via google and doubtless others will too. If you want to fix the position of an iframe the same way you fix the position of a div, you can wrap it in a fixed position div and make it's size 100%.

此代码在整个页面上拉伸iframe,为顶部的菜单留出空间。

This code stretches the iframe across the entire page leaving space for a menu at the top.

CSS:

#iframe_main {
    height: 100%;
    width: 100%;
}

#idiv {
    position: fixed;
    top: 41px;
    left: 0px;
    right: 0px;
    bottom: 0px;
}

HTML:

<div id='idiv'>
     <iframe id="iframe_main"> 
     </iframe>
</div>

这篇关于具有css固定位置的iframe:可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆