【发布时间】:2012-06-22 17:57:58
【问题描述】:
我想通过 CSS 将 iFrame 缩放为width: 100%,并且高度应该与宽度成比例。
使用<img> 标签可以正常工作。
图像和 iFrame 都在 html 中定义了宽度和高度。
这里有一些例子:
<html>
<style>
#a{ width: 500px; }
img{ width: 100%; height: auto }
</style>
<body>
<div id="a">
<img src="http://lorempixel.com/200/150/" width="200" height="150" />
</div>
</body>
这在图像上效果很好,但我希望 iFrame 具有相同的行为:
<html>
<style>
#a{ width: 900px; background: grey;}
iframe{ width: 100%; height: auto }
</style>
<body>
<div id="a">
<iframe width="560" height="315" src="http://www.youtube.com/embed/RksyMaJiD8Y" frameborder="0" allowfullscreen></iframe>
</div>
</body>
iFrame 呈现 100% 宽,但不会像图像那样按比例缩放其高度。
【问题讨论】:
-
到目前为止你有什么?你能做一个jsfiddle吗?让我们看看你的代码。
标签: css iframe responsive-design