Firefox 上带有线性渐变的掩码图像

mask-image with linear-gradient on Firefox

以下代码片段在 Chrome 上完美运行:背景图像逐渐淡入到底部后面的背景中。

div {
  width: 200px;
  height: 200px;
  background-image: url("http://i.imgur.com/wcDxIZG.jpg");
  background-size: cover;
  background-position: center center;
  -webkit-mask-image: linear-gradient(black, black, transparent);
  mask-image: linear-gradient(black, black, transparent);
}
  <div></div>

但在 Firefox 上不起作用,据说该值不正确。

为什么?我该如何解决?

请注意,我知道如何使用另一个 div 作为叠加层,这对我来说不是一个通用的解决方案,因为它对内容和元素有太多影响 position .我唯一感兴趣的答案是修复 div.

背景的答案

我不知道为什么,但是您可以为此使用 :after 属性 复制效果,这适用于所有浏览器 - 甚至我们的老朋友 IE:

.container {
  height: 200px;
  overflow: hidden;
  position: relative;
}

.image {
  width: 200px;
  height: 200px;
  background-image: url("http://i.imgur.com/wcDxIZG.jpg");
  background-size: cover;
  background-position: center center;
}

.image:after {
  content: '';
  filter: progid:DXImageTransform.Microsoft.gradient(gradientType=0, startColorstr='#FAFAFA', endColorstr='#FAFAFA');
  background-image: -webkit-linear-gradient(top, rgba(248, 244, 243, 0) 0%, #fafafa 100%);
  background-image: -ms-linear-gradient(top, rgba(248, 244, 243, 0) 0%, #fafafa 100%);
  background-image: linear-gradient(to bottom, rgba(2248, 244, 243, 0) 0%, #fafafa 100%);
  display: block;
  position: absolute;
  pointer-event: none;
  bottom: 0;
  left: 0;
  width: 200px;
  height: 20%;
}
<div class="container">
  <div class="image"></div>
</div>

从 Firefox 53(2017 年 4 月 19 日发布)开始,由于已经完成了对遮罩图像的支持,现在可以实现了。

http://caniuse.com/#search=mask