【发布时间】:2019-02-24 19:01:58
【问题描述】:
我想在弹出窗口中嵌入来自网站的视频。我希望视频的宽度等于视口的 60%,并自动计算视频的高度以保持纵横比。问题是 iframe 相应地改变了宽度,但我无法让包含的 div 扩展它的高度以完全包含 iframe。
这是我的代码:
#popup {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 20; /* Sit on top */
padding-top: 100px; /* Location of the box */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.85); /* Black w/ opacity */
}
#popup-content {
background-color: #fefefe;
margin: auto;
padding: 0;
width: 60%;
border-radius: 10px;
position: relative;
}
.close {
position: absolute;
top: 0;
right: 0;
color: #ddd;
font-size: 50pt;
text-shadow: 0 0 3px black;
}
.close:hover, .close:focus {
color: #fff;
}
iframe {
border-radius: 10px;
border:0;
padding: 60px 0;
width: 100%;
}
<div id="popup" style="display: block;">
<div id="popup-content">
<iframe allowfullscreen="true" webkitallowfullscreen="true" mozallowfullscreen="true" src="https://www.aparat.com/video/video/embed/videohash/5kInv/vt/frame" width="100%" height="100%"></iframe> <button type="button" class="close"><strong>×</strong></button>
</div>
</div>
【问题讨论】:
标签: javascript html css