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

HTML Introduction to HTML and CSS (2016) Make It Beautiful With CSS Test: Styling by Element and Class

how to.. (css)

pretty simple question. I know there must be a simple, easy explanation. How do I create a rule for .main-pg class in a css file?

index.html
<!doctype html>
<html>
  <head>
    <link href="styles.css" rel="stylesheet">
  </head>
  <body>

    <p class="main-pg">My amazing website</p>

  </body>
</html>
styles.css
p {
  color:blue

1 Answer

Hi Halie,

First, Make sure to close your curly braces and end each property with a semi-colon ;

Your answer would target all <p> tags in your HTML file.

p {
  color:blue;
}

To target a class you start with a dot . So if you would want to target the class main-pg:

<p class="main-pg">My text goes here.</p>
<p class="main-pg">My other text goes here.</p>
<p class="main-pg">And another text goes here.</p>

This example targets all <p> tags because they all have the same class.

.main-pg {
  color:blue;
}

Also sometimes you would need to target a tag with an id (let's name it myId as an example). To target an ID tag you would use #

<p id="myId">My text goes here.</p>
<p id="otherId">My other text goes here.</p>
<p id="anotherId">And another text goes here.</p>

This example targets only the first <p> tag.

#myId {
  color:blue;
}

I hope this helps.

There are many more ways to target your HTML content.