【发布时间】:2021-12-24 07:28:44
【问题描述】:
这是我的 DIV 的开始标签,在 style 属性中带有 SVG 过滤器,并且 SVG 在数据 URI 中编码:
<div class="wpgb-card-media-thumbnail" style="filter: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg"><filter id="multitone_filter_1"><feColorMatrix type="matrix" color-interpolation-filters="sRGB" values="0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0"></feColorMatrix><feComponentTransfer color-interpolation-filters="sRGB"><feFuncR type="table" tableValues="0.4117647058823529 0.0392156862745098 0.9647058823529412"></feFuncR><feFuncG type="table" tableValues="0.7490196078431373 0.054901960784313725 0.8901960784313725"></feFuncG><feFuncB type="table" tableValues="0.6039215686274509 0.058823529411764705 0.5803921568627451"></feFuncB></feComponentTransfer></filter></svg>#multitone_filter_1');">
我的代码基于这篇 Chrome 开发者博客文章:
https://developer.chrome.com/blog/cvd/
唯一的区别是我的样式在 style 属性中。
所以现在根据您对转义的评论解决了第一个代码,但是如果我在我的页面上激活一个方面,则使用该代码和属性中的样式,不再应用过滤器 - 所以我不能使用这个解决方案,这可能是因为它没有被缓存,因为它是内联的,并且我无法激活网格缓存,因为我对我的网格使用了动态查询。 因为我是在页面生成之后,发送到浏览器之前,通过查找和替换替换了DIV标签。
但是这种其他方式也是内联的,它在 Chrome 和 Firefox 中确实有效,你能告诉我为什么这种内联方式在 Safari 中不起作用吗?
div.wp-grid-builder.wpgb-grid-1.wpgb-enabled div.wpgb-card-media-thumbnail {
filter: url('data:image/svg+xml,\
<svg xmlns="http://www.w3.org/2000/svg">\
<filter id="multitone_filter_1"><feColorMatrix type="matrix" color-interpolation-filters="sRGB" values="0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0"></feColorMatrix><feComponentTransfer color-interpolation-filters="sRGB"><feFuncR type="table" tableValues="0.4117647058823529 0.0392156862745098 0.9647058823529412"></feFuncR><feFuncG type="table" tableValues="0.7490196078431373 0.054901960784313725 0.8901960784313725"></feFuncG><feFuncB type="table" tableValues="0.6039215686274509 0.058823529411764705 0.5803921568627451"></feFuncB></feComponentTransfer></filter>\
</svg>#multitone_filter_1');
}
【问题讨论】:
-
尝试转义
-
\"不起作用。似乎正确的方法是使用&quot;。参考:stackoverflow.com/questions/4015345/…
标签: css svg svg-filters