📌 If there are two or more conflicting CSS rules that point to the same element, the browser follows some rules to determine which one is most specific and therefore wins out.
🎯 Specificity Hierarchy
⇢ Every CSS selector has its place in the specificity hierarchy.
⇢ Four categories define the specificity level of a selector:
if the same rule is written twice into the external style sheet, then the lower rule in the style sheet is closer to the element to be styled
That's the reason for the red bg of div
⦿ ID selectors have a higher specificity than attribute selectors
⇢ Start at 0, add 100 for each ID value,add 10 for each class value (or pseudo-class or attribute selector),add 1 for each element selector or pseudo-element
→ The specificity of A is 1 (one element selector)
→ The specificity of B is 101 (one ID reference + one element selector)
→ The specificity of C is 1000 (inline styling)
Since the third rule (C) has the highest specificity value (1000),this style declaration will be applied
⇨ When we code in javascript there are some errors in that code that we are not able to see and even we don't get an error in the browser for that syntax errors.
⇨ But that syntax error affects later in the coding process.
○ Example :
Num = 5;
console.log(Num);
Above☝️, No Declaration, just Initialized but still Working with this syntax error.