by madethemcry · 10y ago · 0 comments
!important should be banned. !important divides the good guys from the bad guys. Whenever I see code with !important I instantly know that guy was lazy, unexperienced, wrong guided - you name it. And it also makes my life hard if I have to continue to work on that same css.
I also miss one of the most useful methods to be more granular with the cascading. To apply a new rule, instead of using a fresh new class or to hammer into some new style definitions with an id/!important just use the class twice in your css. More of the same class means more important.
.button.button.button outranks .button.button which outranks .button.
See here for an example:
http://codepen.io/gkey/pen/ONevEeIt's not beautiful and if you're doing css right you won't need it most of the time. But try this before using the big bad boys like an #ID or the !important statement.
This is even crazier than using an "!important" once in a while. You're creating obfuscated CSS that technically respects the concept of cascades and specificity. Yet your reason for doing this is essentially just to avoid "!important", while not actually fixing your cascading/specificity problem. I'd rather see the rare "!important" as a visible warning sign that something was lazily patched, rather than a poor workaround that is invisible.
This kind of solution sounds a lot like I get in trouble for using "!important", so I'll use an alternative dirty hack that is hidden well enough that I probably won't get caught.
Various other scenarios similar to above is not uncommon for frontend developers to find themselves dealing with in the workplace.
In 90% of situations, the [avoid !important] rule is a good one. By and large, we’re much better off following it than not following it. But there will definitely be situations that fall outside of that 90%."
Sooooo, I guess 10% of the time he's driving dying people to a hospital. DON'T TAKE DRIVING ADVICE FROM AMBULANCES!!!!!
Your narrow mindedness on the scope of issues that could be at play makes me doubt your abilities.
[EDIT] I am slightly jesting by reflecting your comment judging others based on few factors
As such, it has legitimates uses in rare cases (a responsive websites with some javascript style changes specific to a breakpoint per exemple.)
I would personally say that what divides good and bad guys is opinionated though.
When you're already reflecting about !important, well then you're happy to use it, because you think and know about all the consequences. HN readers reflect a lot. So you're clearly the wrong audience.
I'm sorry for my harsh 'lazy and not so experienced' expression. But sometimes you have to exaggerate to be heard.
Those developers I'm talking about just don't think about the consequences. !important is not a tool for them, it's their last resort to fix something. And then? Well it's a dead end and the rise of all the problems with !important we are talking about. If they would know about chaining, they would have used chaining before using !important. It would be a mess too. Yes. But at least it's not a dead end for them and for any other developer who have to contribute to the same codebase.
.buffalo.buffalo.buffalo
yes?