Re: [selectors4] Do we really need `:any-link`?

On 2/6/2016 10:15 AM, Yannick Ihmels wrote:
> Why do we need an additional pseudo-class `:any-link`, if we could simply write `[href]`? There are no issues with specificity, because they are equally specific [(0, 1, 0) vs. (0, 1, 0)]. You could also write `:matches(:link, :visited)`. That’s clearer than a pseudo-class named “any-link”.

In HTML, :any-link isn't equivalent to [href]; it's equivalent to 
"a[href], area[href], link[href]". [href] ends up selecting things like 
base[href].

As for your question, I think this pseudo-class was inspired by people 
misusing the history pseudo-classes in the form of ":link, :visited" to 
match text links instead of a[href]. It doesn't make sense to use 
history-based pseudo-classes when you don't care about the history 
state. I'm guessing that practice arose as a consequence of the :link 
pseudo-class being misnamed; it should be named :unvisited. (I'm 
guessing the misnomer originates from the HTML 3/4 link attribute of the 
body element.)

That explains the bizarre behavior of this pseudo-class: it selects 
elements that are so dissimilar (e.g., a, area, and link) that you 
wouldn't want to style them the same or at all. It makes sense for 
history pseudo-classes to have those elements in common. It doesn't make 
sense for a pseudo-class that people only expect to match text links.

That said, :any-link might be marginally useful in mixed namespace 
documents. HTML, MathML, and SVG are now integrated languages. You need 
"a[href], svg|a[*|href], mathml|*[href]" in a namespaced style sheet to 
select all text links in an HTML document containing all three 
languages. The :any-link alternative is "*|a:any-link, mathml|*[href]". 
This seems like a pretty uncommon situation though; you need to be using 
HTML links /and/ SVG links in an SVG-within-HTML or HTML-within-SVG 
document /and/ want to style the links the same to get any mileage out 
of :any-link. In any other situation that I can think of, :any-link ends 
up making a selector more verbose, not less.

Overall, I don't think this pseudo-class is particularly useful.

Received on Tuesday, 23 February 2016 23:52:10 UTC