Class and Tag Selector, which one comes first?


I got stuck in CSS 13: Nested Elements. What’s the difference between h5.description and .description h5? Why in one problem the tag is written first but other time the class should be written first? Please help.


these two selectors target very different things, h5.description targets all h5 elements with class description, while .description h5 targets all h5 elements nested inside an element with description class. example:

h5.description {color: red; }
<h5 class='description'>hello</h5>
<h3 class='description'>hello</h3>

see? Only h5 elements with description class are targeted. Now for .description h5:

.description h5 {color: red; }
<h5 class='description'>hello</h5>
<div class='description'>


Thank you. It makes sense. I think I need some more time to let the knowledge sink in.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.