Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

Using Combinations in Selectors

Hi im doing a code challenge -Create a child selector to target the anchor element that is a direct child of the div. Set its colour to green and font weight to bold = I put .div > a { color: green; font-weight: bold; }

5 Answers

.div > a { color: green; font-weight: bold; }

This is selecting all "a" elements that are a direct descendent of class "div"

div > a { color: green; font-weight: bold; } /* No period before the element */

What you want is to select all "a" elements that are descendant of element "div".

  • foo = element selector
  • .foo = class selector
  • #foo = id selector

Nice one Chris,

thanks for pointing that out, i missed it.

Hi Deirdre,

What is the error message you are getting?

is this what your code looks like?

.div > a { color: green; font-weight: bold; }

if your code looks like this, i don't see a problem.

This is the answer im getting - this is the child combinator > and the color is green

i have been having the same problem of my code not being accepted, but when i logged out and logged back in a while later the exact same code was excepted.

when i moved onto the 3rd of three, i encountered the same problem again. I have contacted support, i suggest you do the same.

Create a child selector to target the anchor element that is a direct child of the div. Set its color to green and font weight to bold. my answer: .div > a { color: green; font-weight: bold; } not being accepted. Getting error: The child combinator is >, make sure the color is set to 'green'. Am I doing something wrong. I have tried logging out and logging back in. Nothing seems to work.

i figured out my problem. I forgot to give the DIV a class name. <div class="main"> and then i created my child element: .main > a { color: green; font-weight: bold; }