如何获取iframe占据全宽(即显示像div) [英] How to get an iframe to occupy full width (i.e. display like a div)
问题描述
我想让 iframe
的行为像一个正常的非浮动 DIV
。即占据父节点的全宽。这可能吗?寻找等同于 display:div;
I'm trying to get an iframe
to behave like a normal non-floating DIV
does. i.e. occupy full width of parent. Is this possible? Looking for something equivalent to saying display: div;
编辑没有找到 width:100%
,因为我在左边有另一个浮动元素。非浮动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.
工作:使用 DIV
在右侧 - http://jsbin.com/onaxax/1/edit
Working: With a DIV
on the right - http://jsbin.com/onaxax/1/edit
不工作:右侧有 IFRAME
- http://jsbin.com/erapuv/1/edit
Not Working: With an IFRAME
on the right - http://jsbin.com/erapuv/1/edit
推荐答案
您必须用 overflow:hidden
在iframe的元素中包装,这将占用剩余空间,而将iframe的宽度设置为100%。
You have to wrap your iframe in element with overflow:hidden
that would occupy the remaining space, and than set the iframe's width to 100%.
示例。
这篇关于如何获取iframe占据全宽(即显示像div)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!