The priority of using styles is determined by more complex algorithms than just the order of inclusion in HTML. CSS style is selected using the most specific selection rule, where the built-in rules are considered more specific, and then tied to the appearance, then selected by identifier, then class and at the end of the selection with the tag name. For example, the paragraph <p id="xyz" class="xyz"> will be red regardless of the order of the rules:
.xyz { color: blue; } #xyz { color: red; }
If there are two rules with the same type of choice, it matters. So, choosing .xyz .abc “stronger,” then .qwerty .
If the two rules have an equivalent choice in terms of numbers in each category, then in the very final order it is taken into account ...
You can also force another order using the !important directive.
Read more about it with the keywords "CSS Specificity".
source share