W3C home > Mailing lists > Public > www-style@w3.org > January 2010

Re: [css3-selectors] Grouping

From: Tab Atkins Jr. <jackalmage@gmail.com>
Date: Sat, 9 Jan 2010 17:55:00 -0600
Message-ID: <dd0fbad1001091555i1ba3425byf42d118bb1f7f166@mail.gmail.com>
To: Brad Kemper <brad.kemper@gmail.com>
Cc: Fran├žois REMY <fremycompany_pub@yahoo.fr>, fantasai <fantasai.lists@inkedblade.net>, Nikita Popov <privat@ni-po.com>, news <news@terrainformatica.com>, www-style list <www-style@w3.org>
On Sat, Jan 9, 2010 at 12:53 PM, Brad Kemper <brad.kemper@gmail.com> wrote:
> On Jan 9, 2010, at 2:36 AM, Fran├žois REMY wrote:
>> What you're speaking about now *IS NOT* the
>> original meaning of :matches selector. It has been
>> introduced in this mailing list for another purpose.

The name has been suggested for more than one thing.

>> p:matches(a:hover) was introducted to match any
>> P tag that contains an element matching "a:hover"
>> in it. The :has() syntax has been used too.

Indeed, and :has() is a good name for it.  It reads well, and it's
what jQuery currently uses for that functionality.  Thus lets keep
discussing :matches as being what this thread is about - matching an
element that matches any of the provided selectors.

> I think that the way fantasai described it is compatibly with what what you expect; it is just a matter of a space changing what it filtered by the match.
>
> So, for instance, to "select a P tag that contains an element matching 'a:hover' in it", you would add a space after the p:
>
> p :matches(a:hover)

No, that selects something different.

p :matches(a:hover)
is equivalent to
p a:hover
(because putting a single thing in :matches() is equivalent to not
using it at all, except for a specificity increase)

Just remember that :matches is the opposite of :not in all ways.  If
you can use :not to avoid selecting something, you can use :matches to
select it.

p :has(a:hover)
is quite different.  It matches an element which has an a:hover
descendant, and has a p as an ancestor.

Remember, CSS *always* moves forward and down in the DOM tree, with
the matched element being the most forward or down thing that it looks
at; the only combinators are child, descendant, sibling, and adjacent
sibling (>, [space], ~, +).  :has() is the very first thing to violate
that rule (it lets you match an element based on stuff further forward
or down the tree), which is why it hasn't been implemented yet - it
breaks some important optimizations in browsers' matching algorithms.

~TJ
Received on Saturday, 9 January 2010 23:55:32 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 17:20:23 GMT