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 CSS Basics (2014) Basic Selectors Class Selectors

1 Answer

Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,735 Points

The id styles will overrule the class styles, because id's have higher specificity in CSS, but it isn't necessarily a bad idea to use both id's and classes together.

For example, you could have a class for all your buttons for certain default styles, and then an id for a specific button. Let's say I want all my buttons to have a certain padding and border radius, and they will default to be blue, but I'll overrule that for specific buttons:

.button {
  border-radius: 5px;
  background-color: lightblue;
  padding: 10px;
}

#cancel-button {
  background-color: red;
}
<button id="cancel-button" class="button">Cancel</button>

My cancel button will end up with the default properties from the button class (border radius, padding) but will have the red background color from it's id styles, not the default lightblue.