Suggestion for new link pseudo-class, “:current”

[ music | 12 – Duran Duran – To Whom It May Concern ]

Today I sent out an email to the WWW-Style Mailing List. I’m sure most Mozillians don’t read it, however, so I’m reposting it here for comments, opinions, etc. Please leave your thoughts in the comments as I’m interested in everyone’s opinion on this.

It's entirely possible I'm an idiot, however, I think I see an opportunity for a useful addition to the link pseudo-classes.

http://www.w3.org/TR/CSS2/selector.html#x275.11.2 The link pseudo-classes states:

"The :link pseudo-class applies for links that have not yet been visited."

"The :visited pseudo-class applies once the link has been visited by the user."

Recently I've been building a site, and using a new idea on a navigation menu. Once you get beyond a few pages, it's tedious to manage a code block between pages, so one resorts to server side scripting to manage it. In this case, the current page's entry in the menu is styled differently than the rest to indicate the user's current location in the site.

However, I realized that maybe rather than changing the menu HTML server side, I could just use a pseudo-class and style it differently, as one can have unvisited and visited links styled differently automatically by the browser. To my dismay, I discovered there is currently no method to do this.

My idea, which I'm certain has been bandied about a dozen times before, is to add a :current (or some other name) pseudo-class that refers only to URLs that match the currently loaded page, and can be styled differently like :visited and :link. Already browsers have to determine if an URL is unvisited or not, so I don't really see that this additional check would be a greater onus than what they already do, and it could make life a little easier on developers, less server side scripting.

Comments? I'd love to hear support, but also I'd like to hear why this would be a bad idea.

Thanks.

Comments

I never received your msg from the mailing-list. Are you sure you correctly subscribed ?

Anyway, please see this URL : http://www.w3.org/Style/Gro

I suggested that back in 1998…

Yes, I just now got the "please confirm" for archiving message, so it should go out the the membership soonish.

Also, I’d love to see that URL, but it requires authentication. 🙂

1998, eh? Sounds encouraging…

Sounds like a great idea, except…

You would need to have some way to apply a the style to a surrounding block as well. If you could associate a url with arbitrary html elements then it might work.

Then you could add an href element to a div, for example, which would have no effect except that it could be used to determine the CSS style.

So, I see a problem here that just having this pseudo-class won’t get it implemented anywhere. And if (particularly!) MSIE users can’t see what you coded, most designers will fall back to server-side scripting again to make it show up for theses users as well. And the overhead of doing it in two places will probably (and sadly) prevent adoption of it.

On another side note, please don’t publish your commenters’ email addresses, in particular not in plain text in the source of the page, ’cause that’s an invitation for spammers to harvest them.

how does it play with the risk of security issues? My initial thought is – hey! so easy to bruteforce check what websites you have open in other tabs/windows…

I have mixed feelings about this.

Pro: there is certainly demand for something like this. Indeed, more than once have I seen people complaining that the :active pseudoclass does not do what they expected (‘selecting’ the current page), so it’s probably not too far-fetched.

Con: one of the advantages of server-side scripting is that it easily allows you to make sure the menu entry for the current page *is not even a link*. Thus, the current page can easily be distinguished, even when CSS is not applied (keep in mind that CSS is designed to be optional). Plus, I always get confused when a page links to itself – or maybe that’s just me 🙂

I agree with Raf; I’d rather continue to discourage page authors from making pages link to themselves. See http://www.useit.com/alertb… #10 for some additional reasons that avoiding self-links is good usability practice.

That said, I don’t agree with some of the objections mentioned here:

Gandalf, this feature would not introduce a privacy issue, because it would only apply to the URL loaded in the current tab.

Ami, your problem with this feature can be solved by using display:block links 🙂 They’re easier to click, too.

Nice idea, but you’d run into difficulties identifying the "current" page on any but the simplest sites.

How would you avoid the problem of get/post variables? For index.php?referrer=abc you would probably want to match on index.php, but for page.php?id=123 the id parameter is important. Then of course you’ve got index.php?id=123&referrer=abc 😉

Also, what about domains and sub-domains? Are http://www.mydomain.com/ind… and http://mydomain.com/index.html the same page? What about http://www.mydomain.co.uk/i… Or http://www.mydomain.com/?

Maybe some form or regular expression, but then you’re getting to the point where its probably easier just to use server-side scripting.

Ian Thomas got it straight to the point: unfortunately, it’s not really that simple to tell what links effectively point to the current website (and he didn’t even mention anchors).

I love this idea. I have had the same idea and to be honest I am really surprised that there isn’t :current pseudo-class

Comments are closed.