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

brad helman
PLUS
brad helman
Courses Plus Student 290 Points

trouble with css <p> border

i have tried this on my own several ways in html and css googled it but cant find anything on borders with examples in context

index.html
<!doctype html>
<html>
  <head>
    <link href="styles.css" rel="stylesheet">
  </head>
  <body>
    <style>
      <p> {border-color: red;
        border-width: 4px; }
    </style>

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

  </body>
</html>
styles.css
main-pg
.main-pg {}

3 Answers

Denis Arambasic
Denis Arambasic
3,184 Points

There are Three ways to insert css to your web page:

  1. External style sheet (that is this line that you put in the head tags in the index.html file):

    <link href="styles.css" rel="stylesheet">

- than you create that style.css file and put your style there (to make a border on the p element):

    p {
        border-style: solid;
        border-color: red;
        border-width: 4px; 
    }
  1. Internal style sheet (is when you put your css into style tags in the head tag of the index.html file)

    <!doctype html>

    <html>

    <head>

    <style>
    
      p {
        border-style: solid;
        border-color: red;
        border-width: 4px; 
        }
    
    </style>
    

    </head>

    ..

  2. Inline style (is when you put your style directly into your html tags)

    <p style="border-style: solid; border-color: red; border-width: 4px;">My amazing website</p>

if you wont to use the class "main-pg" Inside the paragraph <p class="main-pg"></p> than you can target this element in your style sheet in two ways:

p.main-pg {
    border-style: solid;
    border-color: red;
    border-width: 4px; 
}


.main-pg {
    border-style: solid;
    border-color: red;
    border-width: 4px; 
}

And if you wont to give a element a border first you must define the border-style: solid, dotted, dashed...

Try removing the < and > symbols from the p selector inside the <style> tags. In CSS, the < and > symbols are not put around selectors.

I think the styles are supposed to be in the styles.css. And you are supposed to use the class of the p element when writing the styles