Specifics of Inherited CSS Properties

What is the level of CSS specificity obtained by inherited properties? I read the W3 recommendation regarding CSS specificity, and therefore I understand how to calculate the various features of CSS rules that directly target the same element, but I don’t see any mention of the level of specificity set for the inherited attributes.

In particular, the problem I am facing is related to header elements, although it would be very interesting for me to understand this as a whole.

For example, here is an HTML snippet:

<h2>This should be black</h2>
<div class="all_red_text">
    <h2>This should be red</h2>
</div>

Now, if I include some CSS like this:

.all_red_text { color: red; }

I will get the expected result. On the other hand, if I css, which I included was

h2 { color: black; }
.all_red_text { color: red; }

. CSS , , , , .

0
3

, , , . .

+3

CSS :

Priority 1: inline styles
Priority 2: CSS ID styles
Priority 3: CSS class/pseudo-class styles
Priority 4: CSS element styles
Priority 5: Inherited styles

, HTML CSS

<h2>This should be black (and is black)</h2>
<div class="all_red_text">
    (This text is indeed red.)
    <h2>This should be red (actually, it parent is red - this text is black)</h2>
</div>

h2 { color: black; }
.all_red_text { color: red; }

CSS .all_red_text , div.all_red_text . CSS h2 h2 . h2, , " , , , ". , HTML . , , font-family html ( ) -, - .

, h2 div.all_ted_text , h2, ; - :

.all_red_text h2 { color: red; }

CSS-Tricks , .

+2

CSS. , , .

h2 , h2 { color: black; }. , h2 ( , ). , ( h2), .

h2 { color: black; } , , h2 . color .

0

All Articles