Advertisement
tommyosheawebdesign

CSS Child Combinator

Jun 10th, 2020
1,388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 1.14 KB | None | 0 0
  1. > is the child combinator, sometimes mistakenly called the direct descendant combinator.1
  2.  
  3. 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.
  4.  
  5. An illustration:
  6.  
  7. <div>
  8.     <p class="some_class">Some text here</p>     <!-- Selected [1] -->
  9.     <blockquote>
  10.         <p class="some_class">More text here</p> <!-- Not selected [2] -->
  11.     </blockquote>
  12. </div>
  13. What's selected and what's not:
  14.  
  15. Selected
  16. This p.some_class is located directly inside the div, hence a parent-child relationship is established between both elements.
  17.  
  18. Not selected
  19. This p.some_class is contained by a blockquote within the div, rather than the div itself. Although this p.some_class is a descendant of the div, it's not a child; it's a grandchild.
  20.  
  21. Consequently, while div > p.some_class won't match this element, div p.some_class will, using the descendant combinator instead.
  22.  
  23. 1 Many people go further to call it "direct child" or "immediate
  24.  
  25. REF https://stackoverflow.com/questions/3225891/what-does-the-greater-than-sign-css-selector-mean
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement