Wednesday, 28 August 2013

Why I hate !important

So you're dealing with legacy code.  You've got to apply a new skin, and that's what CSS is all about, right?  Applying a new stylesheet and whaboompf you have a new spanky site with little to no HTML changes (see Zen Garden for a good reference).  Fabulous.

Occasionally you come across a site that's been built by a developer who hasn't figured the semantic thing out, and you find you're making declarations like:

.blue{color:red;}

Always a bit uncomfortable.

But nothing, nothing is as bad as:
p{color:green!important}

Oh bane of my life!! Oh curse you developer!!

My p.blue (which is supposed to be red - work with me here) is green.  Everything is green.  And now I have to start liberally sprinkling !importants all over the place.  The natural cascade is lost.  The very notion of !important is lost.

And I have a crazy urge to hunt down and pummel the lazy f-wit that decided green text was aaaall that site was gonna get.

That's why.