Html 如何让 iframe 占据全宽(即像 div 一样显示)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13158883/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 03:39:07  来源:igfitidea点击:

How to get an iframe to occupy full width (i.e. display like a div)

htmlcss

提问by techfoobar

I'm trying to get an iframeto behave like a normal non-floating DIVdoes. i.e. occupy full width of parent. Is this possible? Looking for something equivalent to saying display: div;

我试图让一个iframe行为像一个正常的非浮动DIV。即占据父级的全宽。这可能吗?寻找相当于说的话display: div;

Edit: I'm not looking for width: 100%since i have another floating element to the left. A non-floating DIV would take the rest of the space on the right. This is the behavior i'm looking to achieve.

编辑:我不是在寻找,width: 100%因为我左边有另一个浮动元素。非浮动 DIV 将占据右侧的其余空间。这是我希望实现的行为。

Working: With a DIVon the right - http://jsbin.com/onaxax/1/edit

工作DIV在右边 - http://jsbin.com/onaxax/1/edit

Not Working: With an IFRAMEon the right - http://jsbin.com/erapuv/1/edit

不工作IFRAME在右边 - http://jsbin.com/erapuv/1/edit

回答by Litek

You have to wrap your iframe in element with overflow:hiddenthat would occupy the remaining space, and than set the iframe's width to 100%.

您必须将 iframe 包装在元素中,overflow:hidden这将占用剩余空间,然后将 iframe 的宽度设置为 100%。

Example.

例子