Re: styling order is counter-intuitive

On Wed, May 23, 2012 at 7:59 PM, ricmetal <ricmetalspam@gmail.com> wrote:
> so, i'd like to understand (before proposing a change) to why css styling
> does not follow the order in which classes are added to an element but
> instead an element gets styled in the order classes are found in the
> stylesheet.
> if there's a webpage with an explanation i'd like to read it, so if someone
> could point me there that would be great.
> i find it very counter-intuitive, not to apply styles in the order they are
> added to an element, but i'm sure there's a reason..

There's no particularly strong reason for it.  HTML defines the class
attribute to be an unordered set of classes.  CSS determines which
rules win on an element according to the specificity of the rule,
which only pays attention to the selector used to apply it and the
order in which it appears in the stylesheet.

In other words, it's that way because it makes sense within the
framework of HTML and CSS.  There's nothing wrong with doing it as you
suggest, but it would be slightly less intuitive within the existing
way that the languages work, and changing it would break a *lot* of
pages.

~TJ

Received on Friday, 25 May 2012 17:22:22 UTC