1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

When use !important ?

Discussion in 'Off Topic' started by Allan, Oct 28, 2013.

  1. Allan

    Allan Well-Known Member

    All in the title, in which case you should use !important ?
     
  2. MagnusB

    MagnusB Well-Known Member

  3. Jaxel

    Jaxel Well-Known Member

    CSS will always use the MOST DESCRIPTIVE declaration.

    So...
    Code:
    td { padding: 5px; } // least important
    tr td { padding: 5px; }
    table tr td { padding: 5px; }
    body table tr td { padding: 5px; }
    html body table tr td { padding: 5px; } // most important
    
    If you can, always try to use a more descriptive declaration instead of using !important. However, if you must, there is really no technical harm in using it; don't let people like the author of the above article scare you. The real issue you will have is if you are writing addons, as the code may interfere with some people's skins.
     
    mistypants, Adam Howard and Allan like this.
  4. Allan

    Allan Well-Known Member

    Thanks guys ;)
     
  5. MagnusB

    MagnusB Well-Known Member

    I don't think the article is trying to scare, it is just exemplifying good practice. Using higher specificity over !important is always the better option, and in the long run more maintainable. xF is built up that way, otherwise we could not have had so many shared css classes between completely different elements.
     

Share This Page