I build backends. On the backend, I decide what runs first. The order is mine to write, mine to read, mine to debug.
CSS is the one place in the stack where I don't get to decide. The browser decides which rule wins, and it decides by a precedence table I can read but not rewrite. That is the whole thing to understand about CSS. It is not a styling language with quirks. It is a rules engine, and the surprises only look like surprises until you read the table.
Here is the table, in the order the browser applies it. When two rules disagree about the same element, specificity is the score. An ID selector beats a class selector beats an element selector, no matter where each one sits in the file:
p { color : black ; } .card p { color : blue ; } #main p { color : red ; }
Enter fullscreen mode
Exit fullscreen mode
The paragraph is red. Not because the ID rule came last in the file β it could come first and still win. Specificity outranks position.β¦