IFrame响应问题

时间:2015-08-03 11:56:54

标签: html css iframe

如何使iframe响应全宽

iframe {position:absolute;top:0;left:0;width:100%; height:100%;}
iframe, object, embed {
    max-width: 100%;
}

这是我的代码,但没有工作

注意:

如果我们使用了像素高度(IFRAME标签),那么全宽度正确。但是没有在响应中工作

解决方案是什么?

1 个答案:

答案 0 :(得分:1)

我认为这就是你要找的东西。我假设您使用的是YouTube,只需粘贴其他链接所在的嵌入链接即可。

<强> HTML

<div class="videoWrapper">
    <!-- Copy & Pasted from YouTube -->
    <iframe width="560" height="349" src="http://www.youtube.com/embed/n_dZNLr2cME?rel=0&hd=1" frameborder="0" allowfullscreen></iframe>
</div>

<强> CSS

.videoWrapper {
    position: relative;
    padding-bottom: 56.25%; /* 16:9 */
    padding-top: 25px;
    height: 0;
}
.videoWrapper iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

我使用了本指南:https://css-tricks.com/NetMag/FluidWidthVideo/Article-FluidWidthVideo.php

我在自己的网站上使用了相同的方法,效果很好。希望这会帮助你!

相关问题