I don't know if it's a part of any standard, but at least two major browsers have implemented it:
:-webkit-any-link
in Chrome:-moz-any-link
in FirefoxI can't find any documentation for it. I would like to know its purpose, browser support, and examples of usage.
The :link CSS pseudo-class represents an element that has not yet been visited. It matches every unvisited <a> or <area> element that has an href attribute.
Pseudo means not authentic, false, pretend. Pseudo may also mean having a close resemblance to. The word pseudo is often used with another word, hyphenated, to refer to something that is inauthentic, such as pseudo-science or pseudo-intellectual. Pseudo- is also a prefix used in words such as pseudonym.
What is a pseudo-class? A pseudo-class is a selector that selects elements that are in a specific state, e.g. they are the first element of their type, or they are being hovered over by the mouse pointer.
:any-link
is a new pseudo-class proposed in Selectors level 4, that matches all elements that would be matched by :link, :visited
. From what I see, its main purpose is to simplify selectors that need to select any hyperlinks, since the naming of :link
is misleading; it specifically means unvisited links only, rather than all hyperlinks (which makes it essentially the opposite of :visited
).
For the purposes of :link
and :visited
, WHATWG HTML and W3C HTML5 both define a "hyperlink" as any one of:
An <a>
element that has an href
attribute. This excludes named anchors (that is, <a>
elements without an href
attribute but instead with a name
attribute), which were used traditionally to mark anchors in a page, now superseded by the use of an id
attribute on any element. See named anchors in HTML 4.
An <area>
element that has an href
attribute.
A <link>
element that has an href
attribute.
For example, consider a scenario where links in the page header should be colored differently from all other links:
body > header > a:link, body > header > a:visited {
color: white;
}
Notice the body > header
part is duplicated across both selectors. This seems redundant, but is currently necessary in order to color links in the page header differently from the rest, but regardless of their visited state. This is because body > header > a
is not specific enough which requires using !important
to override anyway, and body > header > a:link
troublesomely only applies to unvisited links.
With the :any-link
pseudo-class, you can simply do this instead:
body > header > a:any-link {
color: white;
}
Specificity is exactly the same as with each individual half, so there should be no issues there.
Of course, since no browser implements it unprefixed yet, that won't work. As an alternative, considering you're most likely working with an HTML document anyway you can just use a[href]
instead, which works in all browsers including IE7+ on top of also being equally specific:
body > header > a[href] {
color: white;
}
There's a much more elaborate explanation regarding the use of a
versus a:link, a:visited
versus a:any-link
versus a[href]
in this other answer of mine.
Like anything else that has a prefix in CSS, :-moz-any-link
and :-webkit-any-link
exist only for experimental purposes, so you shouldn't use them with your sites. Besides, even if you were to use them right now, you'd have to duplicate the rules themselves (and not just the selectors!) since browsers have to drop entire rules on unrecognized selectors, rendering them pretty useless in real-world code!
As of early 2013, no other implementations of :any-link
exist that I know of. I'm unsure as well as to whether this was implemented by the respective vendors and then proposed for inclusion in Selectors 4, or if it was preliminarily specced before the vendors began implementing it, but I don't think that matters.
Speaking of which, be sure not to confuse the :-moz-any-link
/:-webkit-any-link
pseudo-class with :-moz-any()
/:-webkit-any()
, the latter of which is specced as :matches()
instead (possibly to avoid naming confusion?).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With