Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other Using !important rule in media queries

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #173995
    jimmy
    Participant

    Hey!

    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?

    #173996
    nixnerd
    Participant

    I’m not a fan. I think there’s far cleaner and more elegant solutions.

    #174001
    Senff
    Participant

    Normally 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.

    #174003
    jimmy
    Participant

    Not 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.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘Other’ is closed to new topics and replies.