添加颜色叠加到视频背景

时间:2018-02-24 10:59:28

标签: css

如何为这样的视频添加颜色叠加层,如here所示:

enter image description here

到目前为止,这是我的代码:

HTML

<div>
  <div id="outer">
    <div id="home-top-video">
      <video autoplay loop muted width="100%">
        <source src="http://view.vzaar.com/2710053.mp4" type="video/mp4" /> Your browser does not support the video tag. We suggest you upgrade your browser.
      </video>
      <div id="home-text">
        <div><img src="http://marquesslondon.herokuapp.com/images/logo.ee1689ee.png"></div>
        <h3>LIFESTYLE</h3>
      </div>
    </div>
  </div>
</div>

CSS

#outer {
  width: 100%;
  display: block;
  text-align: center;
  position: relative;
  overflow: hidden;
  min-height: 100vh;
}

#home-top-video {
  left: 0%;
  top: 0%;
  height: 100vh;
  width: 100%;
  overflow: hidden;
  position: absolute;
  z-index: -1;
}

#home-text {
  position: absolute;
  left: 50%;
  top: 50%;
  -webkit-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
}

在这里小提琴:https://jsfiddle.net/kggv3213/1/

2 个答案:

答案 0 :(得分:3)

你可以尝试使用渐变背景的伪元素:

/* Latest compiled and minified CSS included as External Resource*/

/* Optional theme */
@import url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css');

#outer {
  width: 100%;
  display: block;
  text-align: center;
  position: relative;
  overflow: hidden;
  min-height: 100vh;
}
#home-top-video:before {
  content:"";
  position: absolute;
  top:0;
  right:0;
  left:0;
  bottom:0;
  z-index:1;
  background:linear-gradient(to right,rgba(65, 0, 255, 0.4),rgba(255, 0, 232, 0.3));
}

#home-top-video {
  left: 0%;
  top: 0%;
  height: 100vh;
  width: 100%;
  overflow: hidden;
  position: absolute;
  z-index: -1;
}

#home-text {
  position: absolute;
  left: 50%;
  top: 50%;
  -webkit-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  color: #fff;
  z-index:1;
}
<div>
  <div id="outer">
    <div id="home-top-video">
      <video autoplay loop muted width="100%">
        <source src="http://view.vzaar.com/2710053.mp4" type="video/mp4" /> Your browser does not support the video tag. We suggest you upgrade your browser.
      </video>
      <div id="home-text">
        <div><img src="http://marquesslondon.herokuapp.com/images/logo.ee1689ee.png"></div>
        <h3>LIFESTYLE</h3>
      </div>
    </div>
  </div>
</div>

答案 1 :(得分:0)

保持简单,只需添加

#home-top-video:before {
    content: '';
    position: absolute;
    height: 100%;
    width: 100%;
    background: rgba(255,0,255,0.2); //Change as per your requirement
}