1

我需要用 css 提供这个图像。必须在图像上放置一个图层。我无法得到完全相同的外观。有针对这个的解决方法吗?它也可以是 SVG 过滤器。

预期结果:在此处输入图像描述

我试过了,但我做不到。

div {
  width: 400px;
  height: 800px;
  background-image: url("https://i.stack.imgur.com/z5W7Q.jpg");
  background-color: rgba(16, 24, 45, 0.8);
  background-size: contain;
  background-repeat: no-repeat;
  background-blend-mode: darken;
}
<div></div>

4

2 回答 2

2

::before将图像设置在 ( ) 下的伪元素 ( div)上z-index: -1,并使用grayscale文件管理器将其转换为黑白。

在 上设置半透明背景颜色 ( rgba(16, 24, 45, 0.8)) div

div {
  position: relative;
  width: 400px;
  height: 400px;
  background: rgba(16, 24, 45, 0.8);
}

div::before {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: url("https://i.stack.imgur.com/z5W7Q.jpg");
  background-size: contain;
  background-repeat: no-repeat;
  filter: grayscale(1);
  z-index: -1;
  content: '';
}
<div></div>

于 2019-07-27T12:42:45.267 回答
0

我很久以后才解决了这个问题。我最好在这里添加它。相关答案

div {
  width: 400px;
  height: 400px;
  background-image: url("https://i.stack.imgur.com/z5W7Q.jpg");
  background-color: rgba(16, 24, 45, 0.8);
  background-size: cover;
  background-repeat: no-repeat;
  background-blend-mode: darken;
  position: relative;
}

div::before,
div::after {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
}

div::before {
  background-color: gray;
  mix-blend-mode: color;
}

div::after {
  mix-blend-mode: overlay;
  background-color: #98aeea;
}
<div></div>

于 2020-07-16T15:13:14.973 回答