For example:
div > p.some_class {
  /* Some declarations */
}
What exactly does the > sign mean?
Answer
> is the child combinator, sometimes mistakenly called the direct descendant combinator.1
That means the selector div > p.some_class only selects paragraphs of .some_class that are nested directly inside a div, and not any paragraphs that are nested further within.
An illustration:
    Some text here
     
    
        More text here
 
    
What's selected and what's not:
- Selected 
 This- p.some_classis located directly inside the- div, hence a parent-child relationship is established between both elements.
- Not selected 
 This- p.some_classis contained by a- blockquotewithin the- div, rather than the- divitself. Although this- p.some_classis a descendant of the- div, it's not a child; it's a grandchild.- Consequently, while - div > p.some_classwon't match this element,- div p.some_classwill, using the descendant combinator instead.
1 Many people go further to call it "direct child" or "immediate child", but that's completely unnecessary (and incredibly annoying to me), because a child element is immediate by definition anyway, so they mean the exact same thing. There's no such thing as an "indirect child".
 
No comments:
Post a Comment