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

标签 css firefox mask

以下代码段在 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 属性来复制效果,这适用于所有浏览器——甚至是我们的老 friend 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>

关于css - Firefox 上带有线性渐变的掩码图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42528548/

相关文章:

html - 为什么 Firefox(移动版)会缩小我的网站?

python - 在 python 中,selenium 模块。如何使用火狐驱动

javascript - 如何在 jQuery 屏蔽文本输入上执行 .select()

html - 从左到右到顶部和底部的 float div,其中左div位于底部,右div位于顶部

javascript - SASS中基于类名的计算

firefox - 在 Firefox 中使用 kineticjs 进行生涩的拖动 Action

c 计算所有可能的子网

css - SASS 编译错误 - LoadError : cannot load such file -- listen/version Use --trace for backtrace

css - 我的 shoutbox 在 Chrome 上消失了?

ios - 在蒙版 UIView 周围添加阴影