:url("foo") and :baseurl("foo") (was :here for Links)

Summary: While I still feel that :here (or whatever you want to call it) is 
too limited to be of much use, this discussion has convinced me that a generic 
mechanism to allow a link to be selected based on the URL it links to would be 
a useful extension to CSS. What follows is a reply that gives my reasons for 
having reached this conclusion and a description of my proposed mechanism for 
doing so.

On 31 Mar 2003 at 22:57, Larry wrote:

> Ernest Cline wrote:
> > I am willing to be convinced that :here is a good idea, but I haven't seen
> > any supporting reasons given as to why it would be.
> If you are as willing to listen as you say you are, please allow me try
> again to describe exactly what the feature is that we've been discussing
> (I guess I didn't explain it very well before). This time I'll give a
> couple examples.
> > I agree that for a user (who has no control over the format that the
> > author  has chosen for his local URLs) [href^="#'} cannot serve as an
> > adequate  substitute for the proposed :here.  However, I have not seen
> > a reason  presented why a user would care about differntiating between
> > links in the  current page and those that are not.  Unless someone can
> > come up with a  reason other than the user might think that its a neat
> > idea, I see this as  being something that would add bloat to CSS
> > without purpose.
> The reason is that it's a huge hassle to acheive this important feature
> with existing methods. Furthermore, because it's somewhat complex to
> achieve, many web authors simply don't bother.
> Here are two examples:
> Example 1:
> Go to the W3C home page, http://www.w3.org.

The major difference between your two examples is that in Example 1 the link 
is changed to being not a link while in Example 2 the link is made to not look 
like a link. Now unless something like the stillborn Behavioral Extensions to 
CSS gets implemented, :here is not going to be able to make a link not be a 
link, so I'll base my reply on Example 2.

> Example 2:
> Go to http://www.zeldman.com.

Well first off, the author could have avoided the use of the ids (assuming 
that attaching CSS was the only use of them) by using a CSS2 selector. (For 
the example given, it would be [href="/"] .) So already in CSS there is no 
need to add to the HTML code (except in the <style> element) to support this 
desired behavior. However, your other point that this requires the CSS to be 
included in every page across the site has validity and needs to be addressed.

Having had a chance to think over this, I can think of two methods, one in 
existing CSS and one that would require extending CSS in a more generic 
manner, that would provide much the same functionality without requiring a 
:here pseudo-class.

Method 1 - .here

This wouldn't do all the work of :here, but it would do most of it

Instead of :here use .here and in each page apply the class here to the local 
links in the source document. This has the same advantage of :here of allowing 
the CSS to only be defined once. It does have the disadvantage of requiring 
the author to include the class on all of those links, but at least for the 
examples you cited there was only one navbar link to deal with on each page. A 
small hassle, but since updating the style can be done in just one place it is 
not a serious one in my opinion.

Method 2 - :url("foo") and :baseurl("foo")

If CSS is extended, then instead of making the extension apply to just one URL 
as :here would do, a more generic mechanism would be desirable.


This applies if the URL of the href of the link is equivalent to that given as 
an argument.  If a specific identifier within the page is wanted, it must be 
given explicitly.  The set of links selected by :url("foo") and  
:url("foo#bar") is disjoint.  However, (assuming that the type of the link is 
"text/html") the selector :url("foo") should match both href="foo" and 
href="foo.html".  The selector :url("") matches the current web document. 


This applies if the base of the URL of the href of the link is equivalent to 
that given as an argument.  A specific identifier within the page need not be 
given given explicitly.  The links selected by the selector :url("foo#bar") 
are a subset of those given by :url("foo").  For example, the selector 
:baseurl("//www.example.com") would apply to any link that pointed to a 
document on www.example.com, while the selector :baseurl("/foo") would apply 
to any page on the server of the current page that was accessed via the /foo 
path of the server of the current page.  The selector :baseurl("") matches the 
current web document and all links to identifiers in it.

One possible use of this would be to give links for trusted sites a different  
appearance than those of other links, and I can think of several others as 
well.  While none of these uses by itself is sufficiently compelling for me to 
be in favor of extending CSS to accommodate it, this generic mechanism is 
broad enough to accommodate them all and others that I have not thought of. 
The set of possible uses is broad enough that I could support this more 
generic extension,

Received on Tuesday, 1 April 2003 05:38:59 UTC