Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

About specificity

Tags:

html

css

In this code I have paragraph that looks like this

<p class="special">
    This is just a test. <em>what color here</em> inheritance work
</p>

I wonder why is not the string "what color here" taking the color from the parent p element. I mean the class special has the specificity value of 10 and a type such as em has a specificity value of 1 so here 10 is greater then 1.

So I mean the color should have been taken from the selector .special

Here is the markup and css

<!DOCTYPE html>
<html>
    <head>
       <meta name="keyword" content="html5. tutorial" charset=utf-8" />
       <title></title>
       <style type="text/css" media="screen">
          em
          {
             font-weight:bold;
             color:red;
           }

          .special
          {
              color:blue;
           }
       </style>
    </head>
    <body>
       <p class="special">
          This is just a test. Is this color <em>red</em> inheriatance work
       </p>
   </body>
</html>

//tony

like image 391
user2658578 Avatar asked Dec 10 '25 21:12

user2658578


1 Answers

The <em> is a separate element inside of .special, so it has its own specificity breakdown. If the code was <em class="special">, the class specificity would apply to the <em>.

like image 74
David Millar Avatar answered Dec 13 '25 11:12

David Millar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!