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

J.R. Champ
J.R. Champ
13,263 Points

Path of element selector in CSS

Is there someone that can explain me why sometimes in css we need to write the whole path to a selector like this :

div#wrap div.header_wrapper div#header div.container div.wrapper_w div#logo a img {

And some other times we can only write the short way to the selector like this

logo a img {

Many thx !

1 Answer

Ivan Burda
Ivan Burda
10,897 Points

Hi Jean,

I have covered enough CSS classes here but I have not come over a need to write the long path to the selector. Honestly, I have never seen it. Based on my experience, if you use an ID or a CLASS, the selectors are very straightforward. If you do not use an ID/CLASS, you may need to write more to choose a specific HTML item such as <a> and not all links. E.g: div div p a However, I think it is always better to use an ID/CLASS if the selector would be too long. Anyway, I am more than willing to read an opinion of somebody more experienced and learn myself.

Good luck with programming, Jean.

Ivan