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) Getting Familiar with HTML and CSS Building Web Pages with HTML and CSS

In <p> element with class="tag location" why use 2 class names in CSS ? 1) .tag{ } 2) .location{}

In video tutorial mention that in order to style <p> tag we use class name"tag location" But in CSS file it displays 2 diffrent class selectors 1) .tag{


2) .location{ }

why to use 2 selectors with difrent names(tag & location) as we defined this class with the name tag location

Dont understand, the usuage of 2 class selectors as class selectors is considered one name "tag location"

We style in diffrent way <p> tag with class selector "tag" & class selector="location"? Because both class selectors are focusing to the same <p> tag

If you could assist,

Thank You

Stavros Sofroniadis

2 Answers

Aakash Srivastav
Aakash Srivastav
Full Stack JavaScript Techdegree Student 11,638 Points

Hey friend Stavros Sofroniadis , you must have noticed that <h1> and <p> have tag class in common .
In addition , <h1> have name class while <p> have location class.
So , all these things have been done , so that similar style can be given to the <h1> element and <p> element on the basis of common class i,e tag and particular styles can be given to them on the basis on specific classes i,e name for <h1> and location for <p> .
For ex: As you can see , both the elements have been centered , so you can set the same style for centering , background-color , color , margin , padding , border , border-radius and much more :

margin: 10px auto;
padding: 8px ;
color: #000;
border: 1px solid #222;
border-radius: 5px;

Also , you can set different background to them on the basis of specific classes:

background-color: #333;

background-color: #888;

Don't relate the examples to the video , as background-color and color are different for both the elements in the video.

But I have given you example so that you can understand .

Hope this helps :)

Brandyn Lordi
Brandyn Lordi
17,778 Points

its important to remember that CSS stands for "cascading .. ". Once you understand this, you will realize that styles can overlap. You can also assign multiple classes to a single element. Here's a fairly simply example you can view in your browser

<!-- create my styles -->
div{border:1px solid black;}

<div class='round'>
This div has round corners

<div class='red-background'>
This div has a red background

<div class='round red-background'>
This div has round corners and has a red background

<div class="round random-class-name-of-my-choosing">
This div has round corners, but it will not be visible