Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Browser reads your CSS from top to bottom and it will apply in the same way..</p> <p>So first you have a rule called</p> <pre><code>.blue h1 { color: blue; } </code></pre> <p>So browser will parse this information and will color your <code>h1</code> as <code>blue</code>, but it goes ahead and it hits second selector which is</p> <pre><code>.red h1 { color: red; } </code></pre> <p>Now, as your <code>h1</code> which is nested inside <code>.blue</code> is further nested inside <code>.red</code> and also, the specificity of both the selectors are same, browser will go ahead and apply <code>red</code> to the inner <code>h1</code>.</p> <p>So what's the solution? </p> <p>If you can, just swap the order of your classes... No? You cannot? than use a specific selector..</p> <pre><code>div.blue h1 { color: blue; } </code></pre> <p><a href="http://jsfiddle.net/N7FcB/3/" rel="nofollow"><strong>Demo</strong></a></p> <p>The above selector is more specific compared to <code>.red h1</code> as it has a <code>class</code>, and 2 elements... so here, browser will pick up first rule as it is more specific, thus overriding your <code>.red h1</code> selector.</p> <p>You can make your selectors specific as much as you need, you can write the above as <code>div.red div.blue h1</code> or <code>.red .blue h1</code>, but just remember, the more specific selectors you use, the more you hit performance bar, also you will end up writing more and more specific selectors inorder to override others, so choose wisely..</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload