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

For .tag and .location, since they both have different background colors and colors, which one is dominant?

.location and .tab are both included in class included in <p>My home is...</p> of index.html. How do you know which one will override the other since they both have the same properties in styles.css?

2 Answers

Caleb Kemp
Caleb Kemp
12,754 Points

As far as I know (and you can test for yourself), when it comes down to a tie like that, the order they are placed will make the difference. So if you had

<p class="tag location">text</p>

if your CSS file was written

.tag{ background-color: blue;}
.location{ background-color: red;}

the background color would be read because the "location" class was placed lower down in the CSS file

if however, you had ordered your CSS file

.location{ background-color: red;}
.tag{ background-color: blue;}

the color would be blue since the "tag" class is now further down in the CSS file. Hope that helps!

Steven Parker
Steven Parker
231,128 Points

For rules of equal specificity, as is the case here, the order determines the setting, with the last taking precedence.

But be aware that specificity is more important than order. For example if the first rule targeted the element by ID, it would still override one that comes later that targets the same element by class.

For more details, see this MDN page on Specificity.

Caleb Kemp
Caleb Kemp
12,754 Points

Good input, and an important thing to keep in mind