treehouse : what would you like to learn today?
Web Design Web Development iOS Development

CSS Hacks Targeting Firefox

Last updated on:

Firefox 2

html>/**/body .selector, x:-moz-any-link {
  color:lime;
}

Firefox 3

html>/**/body .selector, x:-moz-any-link, x:default {
  color:lime;
}

Any Firefox

@-moz-document url-prefix() { 
  .selector {
     color:lime;
  }
}
View Comments

Comments

  1. Permalink to comment#

    Mayb I can test or guess it, but what does it do?

    • It targets only Firefox browsers, so you can make CSS exceptions. You would use it for hacks, to make your site more functional. (If required).

      Most hacks are for I.E., since they can render a lot differently than other browsers.

  2. Permalink to comment#

    Hey,

    thanks for the tip but its not working in Firefox 3.6.x anymore..

  3. Permalink to comment#

    but thius one works!

    .selector, x:-moz-any-link, x:default { color:lime; } /* FireFox 3 */

  4. sistu
    Permalink to comment#

    @tom: thanks a lot! works fine for me!

  5. Mohit
    Permalink to comment#

    Thanks for the information provided.

    Please let me know about Firefox 4.0 and IE9 CSS hacks….

  6. Its very lovey hack for mozilla.

    it has resolved my mozilla-firefox problem.

    Thanks you
    Vindesh Mohariya

  7. IE 9 hack …

    .selector { color: #fff\9; }

    Firefox 4 hacks anyone?

  8. great hack thank you.

  9. ysh
    Permalink to comment#

    uhmm.. what does it do? hehe sorry i’m a newbie to this. :))

    • Riyaadh
      Permalink to comment#

      Elements does not always display the same in IE as it does in Firefox.
      So using \9 on an element will only target IE.

      Example:
      .whatever { margin: 20px 0 0 0;
      margin: 25px 0 0 0 \9;
      }

      In all browsers except IE margin-top will be 20px but in IE margin-top will be 25px.

      Hope this helped you!! :)

  10. maggie
    Permalink to comment#

    Is it possible to use certain classes when FF loads page?

  11. jacvk
    Permalink to comment#

    @-moz-document url-prefix() doesnt seem to be working in Firefox 7. Any other ideas?

  12. mee
    Permalink to comment#

    Mmhhh, if I use the any FF hack with a a:hover or so. It dosen’t work …

    @-moz-document url-prefix() {
    a:focus {padding-bottom: 7px;}
    }

    Has anyone help for that?

  13. mee
    Permalink to comment#

    I solved it. It was a structure problem …
    Thanks for the hot tip :-)

    • ahmet
      Permalink to comment#

      how did you solved it? i’m stuck at it.

    • guest 00
      Permalink to comment#

      @ahmet,

      people won’t reply once their problem is fix, mee is just one of those kind. i’m actually looking for the solution too.

      Cheers

  14. Permalink to comment#

    Great ! thank you.

  15. Permalink to comment#

    do you know how to target FF9 only? I am actually having an issue of CSS rendering differently on Mac and PC using the same version of FF. Never had this problems in the past. Thank you

  16. Permalink to comment#

    nice list. thx

  17. Permalink to comment#

    Awesome and timely. Thanks for the hack help!

  18. Hey Chris,
    Never really had the change to thank you, yours is the first site I go to when I need to learn or find something out on CSS. Your site is invaluable to us web devs. I’ve really learned a lot from your site, keep it up.

    Thanks

  19. Travis
    Permalink to comment#

    This doesn’t appear to be valid

    @-moz-document url-prefix() {
    #divhere {
    color: red;
    }
    }

    The CSS seems to be getting confused with the wrapping brackets which causes it to be invalid, any thoughts?

  20. Travis
    Permalink to comment#

    Looks like it works now, though only if I add !important at the end of the value…. weird. Also of note i am using a scss sheet

  21. Harry
    Permalink to comment#

    Looks great,
    Thanks you so much .
    it’s working fine.

  22. Permalink to comment#

    Great hack. Thank you!

  23. Awesome and timely. Thanks!

  24. Thank you for the post. Worked perfectly. I guess most of the programs we work with (AKA Dreamweaver, CSSEdit, etc) will say an error with this hack since it has a double bracket {.
    At least is what I think happens with CSSEdit when I wrote it there.

    I’ve translated this post to spanish here.

    http://corchoweb.com/2012/codigo/hacks-de-css-especificos-para-firefox/

    Thanks again.

  25. Worked Perfectly :)

    Thanks

  26. Naga

    Any one help me to get solution
    Iam Using this code
    @-moz-document url-prefix() {} – it works in all firefox except Mac
    Please advice me.
    Thanks in advance..

  27. I am using slider to Unlock using jQuery. But doesn’t working well with Firefox. Please tell me What could be the alternative of -webkit-animation for firefox?.
    Thanks in advance !

  28. Dee
    Permalink to comment#

    how do you get this to work if using hover or focus states? thank you.

  29. Suleman
    Permalink to comment#

    When i use this code

    @-moz-document url-prefix() {
    .selector {
    color:lime;
    }
    }

    it works in my pc but when i upload the site on cpanel it does’nt work

  30. Geoff Kendall
    Permalink to comment#

    I’m by no means any sort of web design guru, but I have found over the course of making 25 or so web sites that if there is a difference between Firefox and IE9 and you aren’t being particularly experimental in your use of advanced CSS selectors, it makes sense to check one really basic thing: that your code validates, both html-wise and CSS-wise. Modern browsers really are pretty consistent, especially if you use a reset CSS such as Eric Meyer’s, but they certainly do different things in trying to make faulted code work. So if you didn’t already validate, it is definitely worth taking your code there first. IMHO.

  31. Whats about other web browsers (like Safari and Opera)??

    • Russell Crow
      Permalink to comment#

      This will work in Opera.

      noindex:-o-prefocus, .selector{

      margin-left: 3em;

      }

      For Safari. You need the extra brackets to wrap your selector and rules in the hack for webkit. I’ve noticed as I type this up it’s putting the second set of brackets on the same line. Those two brackets on the bottom need to be on a seperate line.

      @media all and (-webkit-min-device-pixel-ratio:0){
      .selector{

      margin-left: 3em;

      }
      }

  32. SAM
    Permalink to comment#

    It works.. Thanks :-) good Job

  33. Anonymous
    Permalink to comment#

    you are DA BOMB, man !!! Saved my butt.

  34. Permalink to comment#

    That’s great. Only, the code that targets all FF versions doesn’t validate. :(

    • Sorry @chris – no success by using @import, butI usually dont use import since a long time, so why do you do?

      @buelem thx for the link, why we have to do that for all these browsers… where is the time when 2 or 3 browser are up to date and not that much more…

  35. Thanks mate for this help :)

  36. Urooj
    Permalink to comment#

    thank a lot very usefull post for me

  37. Adrija
    Permalink to comment#

    Thanks a lot..its working perfectly..

  38. Gunjan
    Permalink to comment#

    Any specific CSS hack for MAC Chrome ??

  39. Thanks so much for posting this. Such an easy hack but so useful!

  40. Works \o/

  41. Blue Lem
    Permalink to comment#

    Thanks, that works great ^_^

  42. Blue Lem
    Permalink to comment#

    For anyone trying to target opera and safari you might to check this also

    http://www.webmonkey.com/2010/02/browser-specific_css_hacks/

  43. Permalink to comment#

    NIce Work!!!

  44. Permalink to comment#

    i have hard problem in my firefox css width any advice ?

  45. Permalink to comment#

    NIce Work! Thanks!

  46. Chris
    Permalink to comment#

    Has anyone had success using @import inside of moz specific css?
    Something like this:

    @-moz-document url-prefix() {
    @import url(“ff_font.css”);
    }

  47. Russell Crow
    Permalink to comment#

    I would like to have a hack that will target chrome and not Safari. Trouble is they are both webkit platforms. When I target Safari I sort of have to kind of divide the difference between Safari and Chrome.

Leave a Comment

Use markdown or basic HTML and be nice.