我嵌入一个iframe的定义大小{500x320} (只是为了比率),然后我想让父容器自动调整整个iframe的浏览器宽度。
但是,因为我已经定义了宽度和高度,iframe并不是真正地调整父容器的大小或响应。我还附上了一个屏幕截图的iframe是不调整浏览器的宽度。
我做错什么了?
Html:
<div class="container">
<div class="iframe"> </div>
</div>我的CSS:
.container {
width:80%;
height:auto;
}
.iframe {
width:500px;
height:320px;
}

发布于 2020-01-28 08:26:05
您需要直接向iframe添加css。看看这个。
.container {
width:80%;
height:auto;
}
.iframe {
width:500px;
height:320px;
}
.iframe iframe{width:100%; height:100%;}<div class="container">
<div class="iframe">
<iframe width="560" height="315" src="https://www.youtube.com/embed/C0DPdy98e4c" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
</div>
发布于 2020-01-28 08:31:19
你只需要设置宽度:100%,高度: 100%;
.container {
width:80%;
height:auto;
}
.iframe {
width:500px;
height:320px;
}
.iframe iframe{
width: 100%;
height: 100%;
}<div class="container">
<div class="iframe">
<iframe src="https://api.jquery.com/focus/">
</iframe>
</div>
</div>
发布于 2020-01-30 19:48:48
我找到了解决问题的办法。也许我没有正确地问我的问题。任务是保持帧的高宽比,同时允许调整到浏览器宽度的大小。
HTML
<div class="video-container">
<iframe src="http://www.youtube.com/embed/4aQwT3n2c1Q" height="315" width="560" allowfullscreen="" frameborder="0">
</iframe>
</div>CSS:
.video-container {
position: relative;
padding-bottom: 56.25%;
padding-top: 35px;
height: 0;
overflow: hidden;
}
.video-container iframe {
position: absolute;
top:0;
left: 0;
width: 100%;
height: 100%;
}参见钢笔具有纵横比的响应iframe on CodePen
我从本网站找到了解决方案
https://stackoverflow.com/questions/59944000
复制相似问题