March 26, 201313 yr So, this is a bit of a two-part post... On the one hand, this could serve as a "don't do this! ever!" sort of message, and also I think I might need to rant... Just a little bit. First things first, I've blurred the identifying comment at the top of the sheet (I do have some decency), but take note of a few things in this screenshot first: For those of you who don't know Sublime, the sidebar on the right is a thumbnail scrollbar that in this case is showing about three quarters of the document. All the little light blocks in that scrollbar are matches for the '!important' rule I have selected on line 16. This particular document is imported at the core of a collection of .less files in a "custom website template". Why do this? Seriously?? This makes it virtually impossible to create any sort of personalised website based on this theme, especially since it always includes these files. Please, I beg everyone who reads this.. Please put a bit more planning into your stylesheet layout and avoid abusing the !important rule? It's hell for us freelance coders to have to fix the template before we can start fixing the customer's site (which is what we should be doing).
March 26, 201313 yr Ouch! I've always though !important was very "hacky", and probably used when the devloper was too lazy to do it properly. There can be occasions when !important, it exists for reason after all I've never used it though...
March 26, 201313 yr It's almost as if they didn't want you changing the theme. But then why make it a 'custom' one? I (fortunately?) don't do much with pre-made themes but it winds me up when the css for components/plugins has !important all over it, especially when there's nothing the rule would even possibly need to override...
March 26, 201313 yr As WebTam said, it seems as though they've tried to restrict the themes customisation or are just simply unaware of its correct usage. I try to avoid if necessary because 9 times out of 10, the reason it is often used is because of a CSS Specificity issue that the developer is too lazy to work out; if you structure your code well then a developer shouldn't encounter any specificity issues. The only time I ever use !important is if I'm working with social media plugins that reference external stylesheets that can't seem to be overridden (I'm sure they can but !important is an easy fix and it seems semantic enough to justify its use).
March 27, 201313 yr Author @BlueDreamer, I'd hazard a guess and say it's more likely to be from simple misuse rather than laziness... Comparing a well planned stylesheet to one with what feels like each rule in multiple places, each overriding another while hugging an !important clause; the former is actually less work anyway. I have found uses for it though, but I don't think I've ever needed more than one or two !important rules at most in a full site. Even then, I think those cases were simply to override unwanted CSS borders or rounded corners. @WebTam, this template was built on top of the Gantry framework, but I'm not sure where exactly all these rule importance modifiers came from in the first place... I don't use pre-made themes myself either, but I have a friend who's brilliant at the designing sign and learning the coding side, but she gets stuck with it sometimes and sends some work my way (such as in this case). @Alluziion, talking of external stylesheets and !important, another time it may come in handy is when the order in which stylesheets load isn't quite as it should be. But even in that situation, it's still very hacky. I'd rather fix the load order of the stylesheets anyway. I just find it shocking how little pride and effort so many people put into the code they write.. Edited March 27, 201313 yr by ZaLiTH
March 27, 201313 yr The only thing I like about the !important rule is that it has a higher specificity than an inline style. That's useful when you have to modify a page, don't control the markup and someone has used inline styles. I feel that at all other times it shouldn't be used.
Create an account or sign in to comment