html - 用最大高度填充底部

标签 html css

这是 HTML:

<div class="container">
   <div class="wrapper">
      <iframe src="...."></iframe>
   </div>
</div>

包装器 div 具有 CSS: position:relative; 宽度:100%; 高度:100%; 高度:0; 底边距:56.25%; 溢出:隐藏;

iframe 有 CSS:

position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
border: 0;

容器有CSS:

position: relative;
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
margin: 0 auto;
top: 50%;
transform: translateY(-50%);
max-width: 1280px;
max-height: 720px;

我试图在窗口调整大小时保护 iframe 的纵横比 16:9,并保持其最大高度 100% - 67px calc(100% - 67px)。如何同时进行这两项操作?

最佳答案

我遇到了同样的问题。最后为包装器制作了另一个包装器以获得两者的效果。

内部包装器确保纵横比保持不变,因为 padding-bottoms 的值是根据宽度缩放的。 iframe 填充它的容器,外包装提供最大宽度,以便它在 865 像素后停止扩展。

.video-wrapper-wrapper {
    max-width: 865px;
    margin: auto;

    .video-wrapper {
        position: relative;
        width: 100%;
        height: 0;
        padding-bottom: 82%;

        iframe {
            position: absolute;
            width: 100%;
            height: 100%;
            left: 0;
            top: 0;
        }
    }
}

关于html - 用最大高度填充底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35509945/

相关文章:

javascript - 如何将多个图像直接堆叠在一起?

javascript - 验证动态单选按钮 jQuery

html - 在输入文本旁边放一个按钮 - Bootstrap

html - 如何使 <a> 内具有悬停效果的 SVG 图像可点击

javascript - 未捕获的 TypeError 无法读取 null 的属性 'classlist'

html - 当标准模式下单元格内有 iframe 时,Firefox 和 Chrome 会向表格单元格添加 2px 底部填充

html - CSS中获取div、button等的宽度

html - 为什么我的图片将我的文字推到标题下方?

javascript - 如何放置 :hover css in jquery and change image source

javascript - 在移动设计中替换图像的 HTML。喜欢 Paypal.com