【发布时间】:2020-07-22 14:39:40
【问题描述】:
.d1 {
background-color: #f1f2f4;
display: flex;
padding: 4%;
}
.video-container {
flex: 1;
position: relative;
padding-bottom: 56.25%; /* 16:9 */
height: 0;
}
.video-container iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.d1>.text {
flex: 1;
}
<div class="d1">
<div class="video-container">
<iframe src="https://www.youtube.com/embed/Vbg81kc56FU" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
<div class="text">
Test
</div>
</div>
我使用flexbox,它由左右部分组成,宽度相等。在左侧,我正在尝试插入一个应该具有响应性的 youtube 视频,但根据我的尝试,它没有保持其纵横比,但似乎有更高的高度。我该如何解决这个问题?
【问题讨论】:
-
从 iframe 元素中移除 WIDTH 和 HEIGHT 属性。
-
相同的结果...
-
@darkchampionz 您在哪个部分获得更多
height。是.video-container还是.text? -
更新了我的答案...可能会让你更接近一点