Class and Tag Selector, which one comes first?


#1

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.


#2

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:

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

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

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

#3

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


#4

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