全宽vimeo包装背景

时间:2014-01-23 16:41:04

标签: html css iframe video fluid-layout

我正在尝试创建一个全宽iframe vimeo背景,该背景由位于我的body div中的模式覆盖。视频被覆盖覆盖,因此无法点亮。我试过给视频100%的宽度和高度,但没有运气覆盖屏幕..我试图让视频弹出500x250像素。

HTML      

 <div class="video">    
    <iframe src="//player.vimeo.com/video/82123812?title=0&amp;byline=0&amp;portrait=0&amp;color=3a6774&amp;autoplay=1&amp;loop=1" width="960" height="540" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>  
    <div class="overlay"></div> 
</div>

CSS

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

.video .overlay {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: url(../img/overlay-pattern.png) repeat;
}

2 个答案:

答案 0 :(得分:23)

您需要设置iframe的宽度和高度以及其包装。我还为运气添加了一些z索引!

嘿嘿呀,这是一个小提琴:http://jsfiddle.net/n28Ef/1/

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

.video iframe {
    position: absolute;
    z-index: 1;
    width: 100%;
    height: 100%;
}

.video .overlay {
    position: absolute;
    z-index: 2;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%; 
    background: url(../img/overlay-pattern.png) repeat;
}

答案 1 :(得分:20)

此解决方案在完整CSS中使用iframe而不是图像复制css属性background-size: cover

首先,将您的vimeo iframe放入包装器中:

<div class="iframe-wrapper">
  <iframe src="https://player.vimeo.com/video/123456789?autoplay=1&loop=1&byline=0&title=0">
</div>

然后应用这些样式:

/* Makes a fixed background wrapper
which the user cannot interact with */

.iframe-wrapper {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  pointer-events: none;
  overflow: hidden;
}

/* Make the iframe keep an aspect ratio, and
position it in the middle of its parent wrapper*/

.iframe-wrapper iframe {
  width: 100vw;
  height: 56.25vw; /* Given a 16:9 aspect ratio, 9/16*100 = 56.25 */
  min-height: 100vh;
  min-width: 177.77vh; /* Given a 16:9 aspect ratio, 16/9*100 = 177.77 */
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

此外,在Vimeo的情况下, pro 帐户可让您删除播放器的控件。