[html] Apply CSS rules to a nested class inside a div

I don’t know exactly how to apply CSS to a nested element. Here is my example code, but I’m looking for a manual that explains all the rules:

<div id="content">
  <div id="main_text">
    <h2 class="title"></h2>
  </div>
</div>

How can I apply CSS to only the class title, nested inside that particular div?

This question is related to html css

The answer is


Use Css Selector for this, or learn more about Css Selector just go here https://www.w3schools.com/cssref/css_selectors.asp

#main_text > .title {
  /* Style goes here */
}

#main_text .title {
  /* Style goes here */
}

If you need to target multiple classes use:

#main_text .title, #main_text .title2 {
  /* Properties */
}