Answer the question
In order to leave comments, you need to log in
How to calculate the cascading priority and why does it happen that way?
Greetings.
<body>
<div class="article">
<p>Some text is going right here</p>
<p>Another text at the same place</p>
</div>
</body>
p {
color: green;
}
.article {
color: red;
}
Answer the question
In order to leave comments, you need to log in
It seems logical, in one case you apply the style directly to some element, and in the other case it will simply inherit from the parent, the first case should logically be higher.
For several years of site building, I never needed to calculate priority, somehow I had enough knowledge that id is on the mountain, the class goes up the mountain, and the tag itself is at the bottom of the mountain - everything is extremely simple
Assign the article class to one of the paragraphs.
You now have the red color inherited by paragraphs but then redefined to green.
p{} - MORE ACCURATE than .article because it points to the p SAM TAG.
.article is your div.
if you write
.article p {
color: red;
}
nesting
is not affected.
If you assign a new color to p , then the .article color is ignored. Since you are coloring all p elements in the document, it
is correct to write for p tags that are in .article
.article p {
color: red;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question