Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the order or sequence of rules in CSS significant?

Tags:

css

Is the order, or sequence, of rules in CSS significant?

This post says that it matters: Order of CSS rules matters!!!!!!!!!!

I haven't noticed anything about this in the CSS spec.

Should Calculating a selector's specificity say that if-and-only-if two rules have the same specificity, then it's the later of the two rules (i.e. whichever rule is defined after the previous rule) that's the effective rule?

like image 978
ChrisW Avatar asked Jul 07 '09 15:07

ChrisW


2 Answers

Order does matter. If the specificity is equal, the rule declared later wins out. See Cascading Order in the spec:

...Finally, sort by order specified: if two declarations have the same weight, origin and specificity, the latter specified wins. Declarations in imported style sheets are considered to be before any declarations in the style sheet itself.

like image 91
Jason Creighton Avatar answered Sep 30 '22 19:09

Jason Creighton


Your assumption is correct. A CSS rule defined later overrides a previous definition, unless the rule is less specific than the previous one.

To be more clear about the word "override": it adds to the previous style. If a later rule doesn't specify a specific style, the first one still remains valid.

like image 44
Philippe Leybaert Avatar answered Sep 30 '22 19:09

Philippe Leybaert