Information about cookies on this page

Our website uses cookies to ensure the functionality of the website, to collect and analyze information about the performance and usage of the website. Privacy Policy

  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in
  
  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in

Selecting Children

Sometimes you don’t want all the descendants, only the children. That’s what the > sign is for:

footer > p {
	color: purple;
}

The selector footer > p selects the p elements that are children of a footer, that is, directly inside it. See the difference in our footer: footer a selects both links, because they are descendants of the footer. footer > a selects nothing, because the links aren’t directly in the footer, but in the paragraphs.

The main element on our page contains four div elements: the one with the main heading, the two groups and the breeds. Only the first one is its child, though; the other three are inside section. So main div selects all four, while main > div selects only the one with the main heading. Of course, we could also select it by its class, title-background, but let’s try > to see the difference.

Instructions

  1. 1

    Create a rule for main > div that sets text-align: center. Only the main heading will be centered, the text in the groups stays aligned to the left.

Back

13/17

  1. 1. Rules and Comments
  2. 2. Quiz: Rules
  3. 3. Universal Selector
  4. 4. Type Selector
  5. 5. Class Selector
  6. 6. ID Selector
  7. 7. Quiz: Class or ID?
  8. 8. Attribute Selector
  9. 9. Pseudo-classes
  10. 10. Grouping Selectors
  11. 11. Chaining Selectors
  12. 12. Selecting Descendants
  13. 13. Selecting Children
  14. 14. The Cascade
  15. 15. Specificity
  16. 16. Inheritance
  17. 17. Summary
Next

Try it yourself

Do this exercise right here in your browser. No account needed.