CSS彩色滤镜叠加

use*_*147 4 css css3

我正在尝试在图像上创建颜色叠加层,就像在此应用程序中一样(图像上的绿色叠加层):

http://i.imgur.com/4XK9J6G.png

对我来说,看起来他们只是在图像上添加一种颜色.看起来他们正在使用某种绿色过滤器.我怎样才能用CSS模拟这个?

这是我开始的JSFiddle:https://jsfiddle.net/5ar4713h/embedded/result/

HTML:

<img src="http://www.planwallpaper.com/static/images/canberra_hero_image.jpg" />
Run Code Online (Sandbox Code Playgroud)

CSS:

img {
  display: block;
}

/* Filter */
img:after {
  content: "";
}
Run Code Online (Sandbox Code Playgroud)

Pau*_*e_D 12

CSS过滤器的组合将是一种方法,但没有看到实际的源页面,很难确定.

.wrap {
  width: 400px;
  height: 400px;
  margin: 1em auto;
  position: relative;
}

.wrap img {
  -webkit-filter: sepia(100%) hue-rotate(90deg) saturate(400%);
  filter: sepia(100%) hue-rotate(90deg) saturate(400%);
}
Run Code Online (Sandbox Code Playgroud)
<div class="wrap">
<img src="http://lorempixel.com/image_output/nature-q-c-400-400-6.jpg" alt="" />
</div>
Run Code Online (Sandbox Code Playgroud)

或者,一个简单的灰度滤镜,带有透明的绿色覆盖层.

.wrap {
  width: 400px;
  height: 400px;
  margin: 1em auto;
  position: relative;
}
.wrap:after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 50%;
  height: 100%;
  background: rgba(0, 150, 0, 0.75);
}
.wrap img {
  -webkit-filter: grayscale(100%);
  filter: grayscale(100%);
}
Run Code Online (Sandbox Code Playgroud)
<div class="wrap">
  <img src="http://lorempixel.com/image_output/nature-q-c-400-400-6.jpg" alt="" />
</div>
Run Code Online (Sandbox Code Playgroud)


val*_*als 6

如 Paulie_D 答案所示,一种可能性是使用过滤器。

另一种可能性是使用混合模式。

您可以使用亮度,它获取前图像的亮度和后图像的颜色

或者你可以使用颜色,反之亦然。

这仅取决于哪种布局更适合您的需求

body {
  background-color: gray;
}

div {
  display: inline-block;
  width: 360px;
  height: 270px;
  position: relative;
  border: solid 1px black;
  margin-right: 40px;
}

.inner {
  position: absolute;
  left: 50px;
  top: 50px;
  width: 100%;
  height: 100%;
  background-color: red;
  border-radius: 50%;
}

.green {
  background-color: green;
}

.image {
  background-image: url("https://placekitten.com/1000/750");  
  background-size: cover;
}

.color {
  mix-blend-mode: color;
}

.luminosity {
  mix-blend-mode: luminosity;
}
Run Code Online (Sandbox Code Playgroud)
<div class="image">
  <div class="inner green color"></div>
</div>
<div class="green">
  <div class="inner image luminosity"></div>
</div>
Run Code Online (Sandbox Code Playgroud)