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

Corey Hayden
Corey Hayden
11,717 Points

In the css, why use '.col' and not '.primary col' and '.secondary col' ?

Aren't the class names "primary col" and "secondary col"?

3 Answers

Eduardo Vargas
Eduardo Vargas
5,871 Points

Corey Hayden , I think the confusing thing about this exercise is that you have to remember that elements can have multiple classes assigned to them. Each class is seperated by a space.. For example: <div class="class1 class2">

In this exercise, each column was assigned with two classes. On the first column..."Primary" is one class, "col" is the other class. The same goes for the second column, "Secondary" is one, "col" is the other. The reason this is done is because if you want to style each column DIFFERENTLY, you would target the classes "primary" and "secondary" specifically. However, if you want them both to have the SAME STYLE, then you would target "col" because BOTH SHARE THE SAME CLASS. Hope that makes sense bud.

David Olson
David Olson
8,690 Points

Also .col is less keystrokes, which contributes to cleaner code which is always a good thing.

Corey Hayden
Corey Hayden
11,717 Points

Nevermind! I see now that one class label in the tag can designate several class names, each one separated by a space!

Conrad Turuk
Conrad Turuk
5,144 Points

Hey Corey,

If you have two columns that require different stylings (such as float: left and float: right), then you would need to class each column differently. Classes can be named to whatever you would like. I think in the css modules they use the names .primary col and .secondary col; however, you could use a variety of names:

.col-a AND .col-b

.col-1 AND .col-2

.col-left AND .col-right

.moon AND .sun

That last example might be a bad example as it would be hard to understand which html element the css property is affecting. Overall, as long as there is logic behind the class naming, there are no limitations to what you can use.

IF you are using bootstraps; however, there may be specific classes that you would need to use in order to get the css styling you require. If you haven't touched on bootstraps yet, I wouldn't worry too much about it at this time.

Hope this helps :)

Corey Hayden
Corey Hayden
11,717 Points

in the html for this example, the 2 <div>'s are classed as follows: <div class = "primary col"> content </div> <div class = "secondary col"> content </div>

But in the CSS, both are targeted by only ".col {}" As I understand the naming of classes, the names given in the html are "primary col" and "secondary col". so my question is how can they be targeted in the CSS by simply calling ".col" ?