- objective-c - iOS 5 : Can you override UIAppearance customisations in specific classes?
- iphone - 如何将 CGFontRef 转换为 UIFont?
- ios - 以编程方式关闭标记的信息窗口 google maps iOS
- ios - Xcode 5 - 尝试验证存档时出现 "No application records were found"
有没有办法取消或删除fill: currentColor
?
.svg-icon * {
/* Targets all sub-elements so we can deliver icons with a color override of our choice */
fill: currentColor;
}
.svg-icon.iconLogoGlyph * {
/* How do I negate fill: currentColor further down the cascade? */
fill: inherit;
/* I want the natural colors from the SVG */
}
<svg role="icon" class="svg-icon iconLogoGlyph" width="25" height="30" viewBox="0 0 25 30"><g fill="none"><path fill="#BCBBBB" d="M21 27v-8h3v11H0V19h3v8z"></path><path fill="#F48024" d="M5.402 19.101l13.561 1.96.164-2.38-13.256-2.547-.469 2.967zM7.2 12.3l12 5.6 1.1-2.4-12-5.6-1.1 2.4zm3.4-5.9l10.2 8.5 1.7-2-10.2-8.5-1.7 2zM17.1.2L15 1.8l7.9 10.6 2.1-1.6L17.1.2zM5 25h14v-3H5v3z"></path></g></svg>
我有一组使用 SVG 创作的图标。其中一些图标包含带有颜色信息的内联样式。最常见的用例是忽略这些内联填充,并通过在 CSS 中声明 fill: currentColor
让它们继承父级的 color
。但是,在某些情况下,例如我们的 Logo ,我们希望显示这些嵌入的颜色。在其他地方,比如页脚,我们想用我们选择的单一颜色覆盖颜色。
出于原因™,我坚持使用库中的这些类。每个图标都有类 svg-icon
和一个更具体的类,在本例中为 iconLogoGlyph
。
如果我无法触及类,如何仅使用 CSS 来否定 fill: currentColor
?我已经尝试使用 :not
来选择除 .iconLogoGlyph
之外的所有内容,但这不会让我在实际需要时使用 fill: currentColor
fill: currentColor
的反义词是什么?它不是 fill: inherit
或 fill: none
。我需要类似 fill 的东西:只需捕获 SVG 中的内容,哟
🤔
最佳答案
如果您对 SVG 稍作修改,就有一种方法可以使它正常工作。如果你不是这样:
<path fill="#BCBBBB" d="..."></path>
这样做:
<g fill="#BCBBBB"><path d="..."></path></g>
即将所有填充的形状包裹在组中,并在组而不是路径本身上指定填充,然后会发生以下情况:
根据 the spec ,
fill
不适用于 <g>
元素,因此在组上设置此属性不会造成伤害(例如,您不会突然得到一个填充的矩形),并且
fill
是继承的,因此 <g>
的 fill
将适用于 <path>
.
接下来,如果不是*
你用*:not(g)
在您的 CSS 中(在您的特定示例中,仅使用 path
也可以),然后在默认情况下,fill: currentColor
将告诉路径使用当前颜色(并忽略父组的填充值)。在覆盖情况下,您设置 fill: inherit
,您告诉路径返回以继承父项的填充值。
.svg-icon *:not(g) {
fill: currentColor;
}
.svg-icon.iconLogoGlyph *:not(g) {
fill: inherit;
}
<!-- these two SVGs are identical except that the
first one doesn't have the `iconLogoGlyph` class -->
<div style="color: green">
<svg role="icon" class="svg-icon" width="25" height="30" viewBox="0 0 25 30"><g fill="none"><g fill="#BCBBBB"><path d="M21 27v-8h3v11H0V19h3v8z"></path></g><g fill="#F48024"><path fill="#F48024" d="M5.402 19.101l13.561 1.96.164-2.38-13.256-2.547-.469 2.967zM7.2 12.3l12 5.6 1.1-2.4-12-5.6-1.1 2.4zm3.4-5.9l10.2 8.5 1.7-2-10.2-8.5-1.7 2zM17.1.2L15 1.8l7.9 10.6 2.1-1.6L17.1.2zM5 25h14v-3H5v3z"></path></g></g></svg>
<svg role="icon" class="svg-icon iconLogoGlyph" width="25" height="30" viewBox="0 0 25 30"><g fill="none"><g fill="#BCBBBB"><path d="M21 27v-8h3v11H0V19h3v8z"></path></g><g fill="#F48024"><path fill="#F48024" d="M5.402 19.101l13.561 1.96.164-2.38-13.256-2.547-.469 2.967zM7.2 12.3l12 5.6 1.1-2.4-12-5.6-1.1 2.4zm3.4-5.9l10.2 8.5 1.7-2-10.2-8.5-1.7 2zM17.1.2L15 1.8l7.9 10.6 2.1-1.6L17.1.2zM5 25h14v-3H5v3z"></path></g></g></svg>
</div>
您只需将此 SVG 更改为您希望使用原生颜色的图标。始终应该用当前颜色填充的图标不需要更改。
关于css - 否定填充 :currentColor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44295540/
这个问题在这里已经有了答案: Tempered Greedy Token - What is different about placing the dot before the negative l
我想做与THIS相反的事情。换句话说,我该怎么做: SELECT * FROM table1 WHERE col1, col2 NOT IN (SELECT col1, col2
嗨,假设我有这个字符串: var text = "Jackie Chan | Jack Frost | Capt.Jack Sparrow" 我想找到除 Jack Frost 之外的所有 /Jack/
我只想在运行低于 iOS8 操作系统的设备上执行代码块。我做不到: if #available(iOS 8.0, *) == false { doFoo() } 我目前使用的解决方案是: if
我使用 htaccess 来解析对 seo 友好的请求。早些时候我的 htaccess 有这些字符串来解析像 /some/request/ 这样的请求 RewriteCond %{REQUEST_UR
我只想在运行低于 iOS8 操作系统的设备上执行代码块。我做不到: if #available(iOS 8.0, *) == false { doFoo() } 我目前使用的解决方案是: if
我的一个考试题目是: ! ( ! ( a != b) && ( b > 7 ) ) 选择: a) (a != b) || (b 7) 最初,我以为是 D。这是不正确的,我知道为什么。我不明白逻辑
我很难在 Prolog 中寻找关于否定的明确答案,所以如果这是一个明显的问题,我深表歉意: 我正在尝试编写一个简单的代码,从逻辑上说“如果 X 喜欢 Y 并且只喜欢 Y,则 X 和 Y 彼此相爱。”我
假设我有以下字符串: 邮寄至 电话:+358123456 http://www.google.fi 邮箱:foo@bar.fi Hello World 电话 大象 一分钱 链接 猫头鹰 如何在 RE2
如何在 RE2 中为“匹配字符串不以 4 或 5 开头”编写正则表达式? 在 PCRE 中,我会使用 ^(?!4)但 RE2 doesn't support that syntax . 最佳答案 您可
假设我有一个谓词 is_foo?/1在 Elixir 我想在一个将谓词作为参数的函数中使用它,但被否定了。 Elixir 有没有办法简单地做到这一点? 最佳答案 &(!is_foo? &1)应该这样做
假设我想制作一个描述所有整数的 RE。根据定义,表达式为: (+|-)?[0-9]+ 但定义也匹配这些数字:+0, -0, 0045 0045 情况可能可以使用回溯表达式来解决,但是我如何才能从关于。
作为 Javascript 的初学者,我有一个看起来有点奇怪的问题。我正在使用我在网上找到的外部库,我在其中找到了以下代码: if('useHoles' in c){ this.config.u
否定 MySQL 查询的最佳方法是什么,也就是说,无论条件如何,强制它不返回任何记录。 我使用了 AND 1=0 ,它似乎有效,但我有兴趣知道是否有这样的标准。 最佳答案 只需添加一个false条件
我有一个问题:我必须获取所有未在指定时间表中安排的司机姓名。我可以使用以下查询获取指定时间表中安排的所有司机姓名,但我无法否定它。请给我指示如何去做。谢谢。 select drivername fro
我正在做功能测试,刚刚发现了 assert_difference,如: assert_difference('Account.count') do post :create, :account =
考虑这个模式:*.py。它匹配所有以 py 扩展名结尾的路径。现在,是否有可能找到一个匹配其他一切的模式? 我认为这样可以做到:*[!.][!p][!y],但显然 fnmatch.fnmatch总是返
我有以下正则表达式模式:[^\u0001-\u00FF]。这样我就可以验证用户输入不包含“€”等无效字符。 var utfRegex: RegExp = new RegExp('[^\u0001-\u
我尝试使用 vector::erase 和 std::remove_if 从 vector 中删除对象。我有一个外部 namespace 来进行选择: template bool Namespace:
是否有可能/可以实现否定 boost 过滤适配器,例如 std::vector v = {1, 2, 3, 4, 5}; for(auto i : v | !filtered(is_even))
我是一名优秀的程序员,十分优秀!