W3C home > Mailing lists > Public > www-style@w3.org > April 2003

Re: ID selector via attribute?

From: Ian Hickson <ian@hixie.ch>
Date: Tue, 22 Apr 2003 14:58:00 -0700 (PDT)
To: Michael Day <mikeday@yeslogic.com>
Cc: "www-style@w3.org" <www-style@w3.org>
Message-ID: <Pine.LNX.4.50.0304221433340.17255-100000@dhalsim.dreamhost.com>

On Tue, 22 Apr 2003, Michael Day wrote:
> I read this and it's certainly interesting. It seems to me that :has() is
> the most useful aspect, in that it doesn't introduce new syntax (#) and is
> very easy to read:
> form:has(textarea)

It gets a bit confusing with, e.g.:

   h1:has(+ p) /* an h1 that has a p after it */

> However I find :matches() very difficult to understand, and need to
> re-read such selectors several times to figure them out.

That isn't too surprising given the power of the pseudo-class.

> I feel that if such complicated selectors are really necessary, it's
> almost worth bringing in XPath, which would fit more comfortably than
> trying to stretch CSS further.

How is XPath easier to use or understand than the equivalent CSS with
:matches()? (You could just be more familiar with XPath than CSS.) Could
you show the XPath equivalents for the examples at the bottom of:?


(Having said that, some people would like to extend CSS to allow XPath
expressions as well as Selector expressions.)

> Anyway, I'm definitely interested in implementing :has, but will
> probably steer clear of :matches for now, until I run into an example
> where I actually need it.

The :matches() form with '#' at the start is equivalent to :has(), with
the '#' in the middle is equivalent to a :has() followed by a :matches()
with the '#' at the end, and with the '#' at the end it is useful for
checking that there are multiple paths to the element. I'm not actually
sure that the latter is strictly needed. For example:

   :matches(.bar #):matches(.baz #)

...is equivalent to:

   .bar.baz *, .bar .baz *, .baz .bar *

For each additional :matches(... #) you exponentionally increase the
number of selectors you have to put in the list though.

Note: If you do implement this, make sure to do it as :-foo-has(). This is
not yet in a CR spec (it isn't in any spec in fact), and is highly likely
to change at least a bit before getting in a spec, if it ever does.

For example, the current definition makes:


...useless. Nothing that simple should be that useless IMHO. :-)

Maybe the proposal should be changed to imply the # at the start instead
of at the end (so :matches() without # becomes equivalent to :has()).

Ian Hickson                                      )\._.,--....,'``.    fL
"meow"                                          /,   _.. \   _\  ;`._ ,.
http://index.hixie.ch/                         `._.-(,_..'--(,_..'`-.;.'
Received on Tuesday, 22 April 2003 17:56:39 UTC

This archive was generated by hypermail 2.3.1 : Monday, 2 May 2016 14:27:07 UTC