【问题标题】:Inverting the mask property behind an SVG with css [closed]使用css反转SVG后面的掩码属性[关闭]
【发布时间】:2021-02-02 15:33:47
【问题描述】:

我有一个 SVG 并使用带有背景颜色的蒙版来显示 SVG,是否有任何属性可以用来反转蒙版?例如。通常,svg 掩码不会显示任何不在 svg 后面的内容,我怎么能以另一种方式发生这种情况?

我原以为 mask-composite 将是此处使用的属性,但浏览器 (Chrome) 无法识别它

【问题讨论】:

  • 你能举个例子让我们试试。
  • 没有sn-p,我在网站上找不到一个例子,但它很常见,我可能解释得不好。所以你知道那些圆形的社交图标吗?我想反转悬停时的背景和前景色

标签: css css-mask


【解决方案1】:

mask-composite 是您正在寻找的形式,但您需要 chrome 的 perfixed 版本。

例子:

.box {
  width: 100px;
  height: 100px;
  display:inline-block;
  background: red;
}

.normal {
  -webkit-mask: url(https://i.ibb.co/FzmCjLL/Jqtz.png) center/contain no-repeat;
}

.inverted {
  -webkit-mask: 
    url(https://i.ibb.co/FzmCjLL/Jqtz.png) center/contain no-repeat,
    linear-gradient(#fff 0 0); /* we need this extra layer for mask-composite */
  -webkit-mask-composite:destination-out;
  mask-composite:exclude;
}

body {
  background:#f3f3f3;
}
<div class="box normal"></div>

<div class="box inverted"></div>

【讨论】:

    猜你喜欢
    • 2020-10-06
    • 2015-08-03
    • 2017-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-19
    相关资源
    最近更新 更多