Re: [css3-selectors] Grouping

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 UTC