响应式iFrame

时间:2015-01-18 08:21:45

标签: html css iframe

我努力获得回应iframe,但到目前为止还没有... 我提前使用了以下css和html.thanks。



.testme_container {
position: relative;
height: 0;
overflow: hidden;
}
 
.testme_container-16x9 {
padding-bottom: 56.25%;
}
 
.testme_container-4x3 {
padding-bottom: 75%;
}
 
.testme_container iframe {
position: absolute;
top:0;
left: 0;
width: 100%;
height: 100%;
} 

<div class="testme_container">
<iframe src="http://www.gmail.com" allowfullscreen></iframe>
</div> 
&#13;
&#13;
&#13;

3 个答案:

答案 0 :(得分:0)

你能否详细解释一下你想要达到的目标?

我尝试了你的代码并根据你的CSS类(16x9,4x3)的名称来判断它似乎运行正常,但是,你必须使用不同的URL来测试它:

<div class="testme_container testme_container-4x3">
      <iframe src="http://www.w3schools.com/" allowfullscreen></iframe>
</div>

DEMO

www.gmail.com没有显示的原因是,因为Google不允许它显示在iframe中。如果你看一下你可以看到的jsfiddle,我没有改变你的代码,但链接和我添加了类&#34; testme_container-4x3&#34;。

答案 1 :(得分:0)

这个JavaScript函数依赖于jQuery来使页面上的所有iframe响应。它处理视频嵌入以保持其宽高比而无需额外的垂直或水平边距,但您需要确定您在嵌入式视频中使用的宽高比。

https://gist.github.com/dylanvalade/b2ba4eaa99ae7968cfd8

答案 2 :(得分:0)

您实际上可以在本机javascript中执行此操作,而无需依赖jQuery或其他框架/库。 Responsive Iframes对此非常有用。