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 trialJohn Rothra
6,711 PointsWhich is better: a.class, .class a, or .class > a? What's the difference?
Which is better (if either)? Why? What's the ultimate difference?
a.class {}
.class a {}
or
.class > a {}
2 Answers
Seth Kroger
56,413 PointsAll three do different things, none of which are better or worse than the other. The main thing is to realize they are NOT equivalents to each other.
a.class
selects
<a class="class">only</a>
.class a {}
will select
<div class="class"> <!-- or ul, span, etc. -->
<...>
<a></a>
</...>
</div>
or
<div class="class"> <!-- or ul, span, etc. -->
<a></a>
</div>
while .class > a {}
selects:
<div class="class"> <!-- or ul, span, etc. -->
<a></a>
</div>
John Rothra
6,711 PointsThank you for the clarification! Great info!