css选择器没有(规则AND规则......)

时间:2014-12-18 11:25:27

标签: css css-selectors

我想创建一个只与外部链接匹配的CSS选择器。问题是它似乎不适用于:not()中的多个规则。我不能使用多个not(example: ":not():not()") because that becomes || instead of &&)。

内部链接

<a href="#!/something">...</a>

文档链接

<a href="/doc/.../binary/...">...</a>

外部链接

<a href="...whatever...">...</a>

外部链接的CSS选择器与其他类型的链接不匹配。

a:not([href^="#!/"]):not([href="#"]):not([href^="/doc/"][href*="/binary/"]) {}

解释

a-tags NOT startswith hashbang || not hash || not (startswith /doc/ && contains /binary/)

似乎在not()中不可能有多个规则。这可以用另一种方式解决吗?

HTML来自CMS,几乎没有属性。只有&#34; href&#34;和&#34;标题&#34;被允许。如果我不需要使用js遍历HTML并添加类或rel,那将是一个很好的解决方案。

1 个答案:

答案 0 :(得分:2)

你为什么不这样做?

a[href*="//"]:not([href*="yoursite.com"]),
a[href^="#"],
a[href^="/doc/"],
a[href*="/binary/"]{    
  color: red;
}
a{
 color: green;
}
<a href="#!/something">HASH</a>

<a href="/doc/.../binary/...">Binary</a>

<a href="http://yoursite.com">Yoursite</a>