通過使用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這一點。 –