【发布时间】:2014-03-05 21:36:32
【问题描述】:
我正在使用described here 技术使 iframe(视频)具有响应性。本质上,iframe 绝对定位在 100% 宽度的包装元素内。包装元素根据视频的纵横比设置填充:
.embed-responsive {
position: relative;
/* video height / video width */
padding-bottom: 56.2%;
height: 0;
overflow: hidden;
}
.embed-responsive iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
我需要能够将 iframe 在父容器(高度为 100%)中垂直居中。
我在使用 this technique 之前已经实现了这一点,但它只适用于 inline-block 元素。如果我将 .embed-responsive 更改为 inline-block 它会中断。
那么有没有一种替代技术(最好只使用 CSS)我可以用来垂直居中 iframe,同时仍然保持响应?这必须在调整浏览器大小时起作用。
【问题讨论】:
标签: css iframe responsive-design