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 CSS Basics (2014) Basic Selectors Descendant Selectors

i don't know...

i don't know how to target the paragraph that is a descendant of the main-content class

11 Answers

Greg Kaleka
Greg Kaleka
39,021 Points

Hi Richard,

This is actually pretty simple. Let's break it down:

/* To target all paragraphs, you'd write a rule like this: */
p {
    color: tomato;
}

/* To target the main-content class, you'll write a rule like this: */
.main-content {
    display: block;
}

/* To target the paragraph that's a descendant of the main-content class, you'll write a rule like this: */
.main-content p {
    color: blue;
}

To target a descendant of something else, you just write the "parent" element first (in this case the class .main-content), then the descendant (in this case paragraphs), with a space in between.

Make sense?

Viraj Kokane
Viraj Kokane
17,531 Points

Hi Greg how do you post your code in the black box in forum ? CSSThanks Greg for your help.

Greg Kaleka
Greg Kaleka
39,021 Points

Hi Viraj,

When you're commenting, you'll see a link below the text area that says Markdown Cheatsheet. It has some tips for how to style your posts. You can also watch the Tips for asking questions video in the right sidebar ->.

To make a code block like the one above, you just do this:

```CSS

[your code here]

```

Note those are backtics ` and not apostrophes '. You'll find them in the top left of your keyboard, under the ~.

You can replace the "CSS" with whatever language you're using - html, javascript, python, etc.

i can't do a question on a quiz "We define the universal selector with a(n) ______."

Greg Kaleka
Greg Kaleka
39,021 Points

Hi Richard,

I would take another look at the video, or do a quick google search for something like "CSS universal selector" - it's good to get in the habit of finding answers to questions like these :). If you're stuck, post another question in the forum, but I'm confident you'll find your answer in about 10 seconds :)

Greg Kaleka
Greg Kaleka
39,021 Points

Viraj Kokane, you have to put the ``` on it's own line, and the code has to start on a new line as well.

Chris Adamson
Chris Adamson
132,143 Points

It's looking for the main-content selector (prefaced by the dot ',' for classes) followed by the paragraph p selector:

.main-content p {
  font-weight: bold;
}
Viraj Kokane
Viraj Kokane
17,531 Points

Try this It will work: .main-content p { }

to Viraj Kokane: Bummer! i have to Make sure i'm targeting the paragraph nested inside '.main-content'.

Viraj Kokane
Viraj Kokane
17,531 Points

Have you entered the given value in the task.

i know that already

Greg Kaleka
Greg Kaleka
39,021 Points

Great! Just a reminder - these kinds of comments can go in comments instead of new answers :)

yeah that makes sense

to Greg: IT WORKED! You are so the best programmer and oh how did you get to be a MOD

Greg Kaleka
Greg Kaleka
39,021 Points

Great - glad you got it to work!

Treehouse reaches out to students who have some subject-matter expertise (essentially, lots of points :), and are active in the forums, and asks them to be moderators.

Cheers,

Greg

P.S. for future reference, it's better to add a comment to answers rather than posting new ones when you want to reply to someone.

|:(

Viraj Kokane
Viraj Kokane
17,531 Points

CSS.main-content p { font-weight: bold; }

i can't do a question on a quiz "We define the universal selector with a(n) ______."

Viraj Kokane
Viraj Kokane
17,531 Points

Have you solved the quiz ? The answer was: We define the universal selector with a(n) *_."

so it is

.main-content p {
      font-weight: bold
}

i meant

.main-content p {
   font-weight: bold;
}
Greg Kaleka
Greg Kaleka
39,021 Points

Richard - you can edit your comments/answers after the fact by clicking on the rectangle with three dots that's after every post of yours. Helps keep forum threads clean - this one is a mess haha.