【问题标题】:Why should I have to override the webkit stylesheet to create a css rule for an anchor link?为什么我必须重写 webkit 样式表来为锚链接创建 css 规则?
【发布时间】:2018-09-05 01:25:29
【问题描述】:

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

:root {
    color: #4c4e4d;
}

/* this seems excessive to have to 'inherit override' anchor  
links. */
a:-webkit-any-link {
  color: inherit;
}

【问题讨论】:

    标签: css google-chrome inheritance overriding root


    【解决方案1】:

    链接是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中设置字体颜色并不意味着“强制页面上的所有文本都是这种颜色”,而是“在根元素上设置颜色,允许后代继承该颜色为正常”。

    2. Inherited values never override cascaded values no matter where they're coming from and regardless of the specificity of both selectors (specificity doesn't enter the conversation when the selectors are matching different elements to begin with).

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-22
      • 1970-01-01
      • 2021-09-18
      • 1970-01-01
      • 2011-01-15
      • 1970-01-01
      • 1970-01-01
      • 2021-12-12
      相关资源
      最近更新 更多