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
Jason Ruby2,867 Points
ID selector vs. Class selector: Order of Precedence
I am just looking to confirm that I completely understand the application of defined styles as they are applied to ID and Class selectors in the case when an element in an HTML file is identified by both an ID and a Class.
Assuming there are no other styles that are affecting the element in the HTML file the styles applied via the ID will override any style applied through reference of the Class specific to that element.
Is that correct?
Steven Parker228,978 Points
Yes, assuming that only the ID or class are being used as the sole selectors and not combined with anything.
The general rules for CSS specificity are:
- inline is more specific than id
- id is more specific than class
- class is more specific than element
Kevin Korte28,148 Points
The bottom of this article does a great job visually showing you how specificity is calculated.