[csswg-drafts] [selectors] Match local links

LeaVerou has just created a new issue for https://github.com/w3c/csswg-drafts:

== [selectors] Match local links ==
In navigation menus, tables of contents etc there's often a need to highlight the links that point to the current page or a part thereof.
While this is needed in almost every website, it currently cannot be done without JS, server-side coding, or [horrible hacks](https://stackoverflow.com/a/26126610/90826).
Selectors4 used to define a [`:local-link` pseudo-class](https://www.w3.org/TR/2013/WD-selectors4-20130502/#local-pseudo) to solve this issue, but was removed in the latest ED due to lack of interest. IMO that was a good decision, as it was overcomplicated and didn't even cover all common use cases. For example, it ignored fragment identifiers, so it was useless for intra-page navigation.

What about a `:local-link` pseudo-class that works like the following:

1. If the link target does not match the current document URL ignoring any fragment identifiers, the pseudo-class does **not** match.
2. If the link target contains a fragment identifier, the fragment identifier must match that of the current document URL, otherwise the pseudo-class does not match. If the link target does not contain a fragment identifier, step 1 is sufficient.

This definition works for both intra-page navigation as well as navigation across pages, and doesn't have all the path segment complexity of `:local-link()`. Furthermore, authors don't have to think what kind of matching they need — it just works.

Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/2010 using your GitHub account

Received on Saturday, 25 November 2017 02:43:34 UTC