通过使用inline-flex
和虚拟img
有正确的比例,将其设置为visibility: hidden
,然后定位iframe
绝对的,它的工作原理,仅适用于Chrome了,所以必须有一些问题,与其他浏览器,img
没有正确确定其父母的大小。
我会自己发表一个问题,看看有人对此有所了解,并在知道更多时更新此帖。
更新
对于一个固定的高度,即200px
,一个可以将它设置在.container
并添加height: 100%
到.iframe
,它会在其他浏览器(solution provided by Tunçel Mert)工作
不过,如果form-content
的大小基于其内容,但它仍然只能在Chrome上运行。
Fiddle demo
栈片断
.container {
display: inline-flex;
height: 200px;
}
.iframe {
position: relative;
height:100%;
background: red;
}
.iframe img {
height:100%;
visibility: hidden;
}
.iframe iframe {
position: absolute;
left: 0;
top: 0;
height: 100%;
width: 100%;
}
.form {
background: orange;
}
.fake-form-content {
width: 200px;
}
<div class="container">
<div class="iframe">
<img src="http://placehold.it/160x90">
<!-- Sorry about the video -->
<iframe src="https://www.youtube.com/embed/dQw4w9WgXcQ" frameborder="0" width="320" height="180"></iframe>
</div>
<div class="form">
<div class="fake-form-content">
Fake form content
</div>
</div>
</div>
我认为你将不得不使用JS这一点。 –