According to the documentation of Developer.mozilla.org:
Origin is defined in 3 levels
1. Importance
Styles with !important
precedes all others and has higher priority.
Followed comes style defined inline, that is, in the element itself, within style
:
<div style="border: none"><div>
Then the priority is:
Selector by ID: #id {...}
Selector by name of class: .classe {...}
Selector by name of tag: div {...}
2. Specificity
It is measured based on how specific a selector is - how many elements it can combine/achieve.
Has a certain "calculation" to be determined, to understand see the link: Specificity
But one simple way to understand it is: the more specific a selector is the higher its priority. Here’s an example of the link above:
HTML:
<div id="test">
<span>Text</span>
</div>
CSS:
div#test span { color: green; }
div span { color: blue; }
span { color: red; }
In this example, the color will be green, as it is the most specific selector (span
nestled with a div
, with ID="test"
), no matter which order the selectors were declared.
3. Order
In a basic way, if the above criteria do not prioritize the rule, it follows the order that have been declared
Another great font here (in English): www.W3.org
Yes is duplicated from https://answall.com/questions/143850/qual-seletor-css-tem-prioridade and this other may help you https://answall.com/questions/38034/como-se-d%C3%A1-a-preced%C3%Aancia-das-regras-do-css
– hugocsl
@hugocsl Wherever you go you’re there, my god
– I_like_trains
@I_like_trains =D appeared CSS I appear together rss
– hugocsl
@hugocsl thanks Ugo could not find something similar at the time of asking the question, but for being simple I suspected that someone could have asked _(ツ)_/
– vulgogandini