Re: proposal for a new css combinator

Tab Atkins Jr. wrote:
> On Thu, Jan 14, 2010 at 9:24 AM, Øyvind Stenhaug <oyvinds@opera.com> wrote:
>> On Thu, 14 Jan 2010 14:51:16 +0100, Tab Atkins Jr. <jackalmage@gmail.com>
>> wrote:
>>
>>> On Thu, Jan 14, 2010 at 6:41 AM, Alan Gresley <alan@css-class.com> wrote:
>> (...)
>>
(snip)
>> Anyway, syntax-wise a combinator seems more natural than a pseudo-class. I
>> can't think of any other pseudo-class where determining a match depends on
>> what simple selectors there are earlier in the sequence.
> 
> You're right; I knew there was something niggling in the back of my
> brain about it.  Combinators are indeed the way we indicate
> relationships between different parts of the selector; pseudoclasses
> and the like can only tell us special things about the document
> itself, not the selector.  It would be best to maintain that
> distinction.
> 
> ~TJ


I would disagree with you both. Combinator selector have a simple 
relationship between two elements.

<http://www.w3.org/TR/2009/PR-css3-selectors-20091215/#child-combinators>


# A child combinator describes a childhood relationship between
# two elements.


<http://www.w3.org/TR/2009/PR-css3-selectors-20091215/#sibling-combinators>


In the case of sibling selectors, there is also a relationship between 
two sibling elements.

Examples:


div>p

can match the <p> in any example below.

<div>
   <p> .. </p>
</div>

<div>
   <p> .. </p>
   <p> .. </p>
</div>

<div>
   <h1> .. </h1>
   <p> .. </p>
</div>


p+p

can match the second, third, ... <p> in the examples below.

<div>
   <p> .. </p>
   <p> .. </p>
</div>

<div>
   <p> .. </p>
   <p> .. </p>
   <p> .. </p>
</div>


where

h1+p

only matches the first <p> in the examples below. The second , third, 
... <p> will never be matched.

<div>
   <h1> .. </h1>
   <p> .. </p>
   <p> .. </p>
   <p> .. </p>
</div>



Structural pseudo-class are different. :first-child and :last-child 
selects the first or last element of a given type. With Niels Matthijs 
proposal this was for <header> but this could a <p> or a <div>. Unlike 
the structural pseudo-classes of :first-child and :last-child which goes 
across a particular generation of the DOM, :first-descendant and 
:last-descendant would go up or down the tree.



-- 
Alan http://css-class.com/

Received on Thursday, 14 January 2010 16:31:48 UTC