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

Bishwash Shrestha
Bishwash Shrestha
132 Points

how to add border to the p element with external css

how to add class attribute through external css

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
<style>
p.main-pg {border: 4px solid red
}

</style>

1 Answer

Valeshan Naidoo
Valeshan Naidoo
27,008 Points

Your selector needs to be formatted correctly. So if you want to target all p elements which have the class = "main-pg", you can do something like :

.main-pg p {
color: red;
}

If you want to target all p elements in the body then just use :

p {
color: red;
}

Or all elements with the class = "main-pg":

.main-pg{
color: red;
}