为什么不能:root颜色是:root颜色?那不就是那个吗?
:root {
color: #4c4e4d;
}
/* this seems excessive to have to 'inherit override' anchor
links. */
a:-webkit-any-link {
color: inherit;
}
链接是colored differently from the rest of the text by default。在过去的20年里,几乎每个浏览器都做到了这一点;它不是WebKit特有的东西。因此,如果您希望链接与文本的其余部分颜色相同,则需要指示浏览器进行此类操作。执行此操作的惯用方法是使用color: currentColor
而不是color: inherit
,并且跨浏览器兼容的选择器(如果您不打算将此特定于WebKit)是a[href]
。
如果你问为什么作者级别的:root
规则不会覆盖UA级别的a:-webkit-any-link
规则,原因有两个:
:root
中设置字体颜色并不意味着“强制页面上的所有文本都是这种颜色”,它意味着“在根元素上设置颜色,允许后代继承该颜色”。