为什么我必须覆盖 webkit 样式表才能为锚 link 创建 css 规则?

Why should I have to override the webkit stylesheet to create a css rule for an anchor link?

为什么 :root color 不能是 :root color?这不是它的目的吗?

: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 规则,原因有两个:

  1. :root中设置字体颜色不是"force all the text on the page to be this color",而是"set the color on the root element, allowing descendants to inherit that color as normal".

  2. 继承的值无论来自何处,无论两个选择器的特异性如何).