How does a strong selector override the id selector? Is the identifier selector more defined?

in the following snippet, why does the strong selector override the id selector ? Is the id selector more specific, therefore taking precedence?

<!doctype html>
<html>
  <head>
  <title>Sample document</title>
  <style>
      strong{color:red;}
      #abc {color:blue;}
  </style>
  </head>
  <body>
    <p id="abc">
      <strong>C</strong>ascading
      <strong>S</strong>tyle
      <strong>S</strong>heets
    </p>
  </body>
</html>
+4
source share
1 answer

, . , strong, , p . , #abc, :

strong { color: red; }

#abc strong {  color: blue; } 

, strong , p,

#abc, #abc strong { color: red; }

strong { color: red; }
#abc strong {  color: blue; }
#def, #def strong { color: red; }
<p id="abc">
  <strong>C</strong>ascading
  <strong>S</strong>tyle
  <strong>S</strong>heets
</p>
<p id="def">
  <strong>ABC</strong>
DEF
</p>
Hide result
+3

Source: https://habr.com/ru/post/1625889/


All Articles