响应式视频背景:视频对齐

时间:2014-10-07 13:39:23

标签: html css video

我想创建一个响应式背景视频,但不知道如何更改对齐方式。 我可以看到,对齐目前是右下角,但我想将其更改为居中心。 (如背景位置:中心)

有没有办法实现这个目标?

小提琴:http://jsfiddle.net/66dLhjxh/

HTML:

<video autoplay loop poster="http://demosthenes.info/assets/images/polina.jpg" id="bgvid">
    <source src="http://demosthenes.info/assets/videos/polina.webm" type="video/webm">
    <source src="http://demosthenes.info/assets/videos/polina.mp4" type="video/mp4">
</video>

CSS:

video { 
    position: fixed;
    display:block;
    right: 0;
    bottom: 0;
    min-width: 100%;
    min-height: 100%;
    width: auto;
    height: auto;
    z-index: -100;
    background-color:#fff;
    background:url(../img/schrijven.jpg) no-repeat;
    background-size: cover;
    background-position: center center;
}

2 个答案:

答案 0 :(得分:0)

尝试此代码DEMO

<div id="info">
Responsive Youtube embed......
</div>
<div class="holder">
  <div class="video-container">

  </div>
  </div>
<button onclick="nextVideo()">Next Video</button>
</div>

.video-container {
    position: relative;
    padding-bottom: 56.25%; /* 16:9 */
    padding-top: 30px; /* size of chrome */
    height: 0; 
    overflow: hidden;
}

.video-container iframe,
.video-container object,
.video-container #overlay,
.video-container embed {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}
#overlay {
    background:#000;
    opacity:0.5;
    /*background:rgba(255,255,255,0.8); or just this*/
    z-index:50;
    color:#fff;
}

答案 1 :(得分:0)

这是完美的

video { 
    position: fixed;
    display:block;
    right: 0;
    bottom: 0;
    min-width: 100%;
    min-height: 100%;
    width: auto;
    height: auto;
    z-index: -100;
    background-color:#fff;
    background:url(../img/schrijven.jpg) no-repeat;
    top: 0px;
    left: 0px;
    background-size: cover;
    background-position: 50% 50%;
    /*background-position: 30% 50%;*/
}

See it in action.