views:

272

answers:

4

For example:

What does div > p.some_class { ... } selects ?

+1  A: 

All p tags with class 'some_class' which are children of a div tag.

tschaible
+3  A: 

It matches p elements with class some_class that are directly under a div.

dan04
+27  A: 

> is the child selector, or a direct descendant selector.

That means it only selects paragraphs of some_class that sit directly inside a div.

An illustration:

<div>
    <p class="some_class">Some text here</p>     <!-- Selected [1] -->
    <blockquote>
        <p class="some_class">More text here</p> <!-- Not selected [2] -->
    </blockquote>
</div>

Footnotes:

  1. Selected as it's directly within the <div>.
  2. Not selected as it's inside a <blockquote>.
BoltClock
Thanks a lot !!
Misha Moroshko
+1 Is it really called a *child selector*? If so, that is pretty misleading. I would of thought `#something a` would be a child selector.
alex
@alex: [yes](http://www.w3.org/TR/CSS2/selector.html#child-selectors) :) `#something a` could mean `a` is a grandchild or great^n grandchild of `#something` (it doesn't take into account depth of nesting).
BoltClock
@BoltClock Well I mean it is still a child... a grandchild maybe :P
alex
+4  A: 

As others mention, it's a child selector. Here's the appropriate link.

http://www.w3.org/TR/CSS2/selector.html#child-selectors

no
Thank you very much for the link ! I discovered also the "Adjacent sibling selectors" there.
Misha Moroshko
You'll find [browser support](http://reference.sitepoint.com/css/childselector#compatibilitysection) on Sitepoint. Doesn't work in IE6 if it matters for your projects, OK everywhere else. This resource is esp. useful for siblings, :nth-child() etc where support is still incomplete
Felipe Alsacreations