- This topic is empty.
-
AuthorPosts
-
June 28, 2014 at 4:27 pm #173995
jimmy
ParticipantHey!
I’m building a little project for myself right now and it got me thinking – is it a good idea to use !important rule in media queries? Normally I never use it, because as we all know – it sooner or later leads to an incoherent code.
However, media queries inherently ARE overrides of the general CSS code. Can using !important inside them be justified? Not only it seems logical and clean, but can also prevent those lengthy specificity combats.
What do you think?
June 28, 2014 at 4:29 pm #173996nixnerd
ParticipantI’m not a fan. I think there’s far cleaner and more elegant solutions.
June 28, 2014 at 5:05 pm #174001Senff
ParticipantNormally I never use it, because as we all know – it sooner or later leads to an incoherent code.
Not sure about this. You can make very clean and coherent code without ever using !important.
I try to avoid it as much as I can, but very sometimes I really can’t seem to avoid it, especially when I use plugins or frameworks and you have to override defined styles.
I mean, which one is actually worse?
body.page div.some-div div.some-class div.another-class div.yet-another-class div.specific-class ul.some-list li.things a {color:red;}
or
ul.some-list a {color:red !important;}
My point: try to avoid it, but not at all cost. If you have it just once or twice in your entire website….meh.
June 28, 2014 at 5:13 pm #174003jimmy
ParticipantNot sure about this. You can make very clean and coherent code without ever using !important.
That’s basically the same what I said :D
Overriding plugins is an entirely different thing, EVERYTHING is better than changing the plugin’s own stylesheet. Yeah, learned it the hard way…
Without taking media queries case into consideration, I would never even consider using !important, except when emergency OH SHIT mode commences and I need to quickly correct something with an intention of coming back to it eventually.
However, media queries? All they do is overriding general declarations, how is that different? In this case !important is separate enough from the rest of the code to not wreak havoc as it does normally.
-
AuthorPosts
- The forum ‘Other’ is closed to new topics and replies.