Table Of Content
- Using conditional comments it is easy to target Internet Explorer with browser-specific CSS rules:
- Sometimes it is the Gecko engine (Firefox) that misbehaves. What would be best way to target only Firefox with your CSS rules and not a single other browser? That is, not only should Internet Explorer ignore the Firefox-only rules, but also WebKit and Opera should.
- This is probably the most clean and easy solution out there and does not rely on JavaScript being turned on.
- It’s based on yet another Mozilla specific CSS extension.
- Here is how to tackle three different browsers: IE, FF and Chrome
- Here is some browser hacks for targeting only the Firefox browser,
Using selector hacks.
[pastacode lang=”css” manual=”_%3A-moz-tree-row(hover)%2C%20.selector%20%7B%7D” message=”css code” highlight=”” provider=”manual”/]JavaScript Hacks
[pastacode lang=”css” manual=”var%20isFF%20%3D%20!!window.sidebar%3B%0A%0Avar%20isFF%20%3D%20’MozAppearance’%20in%20document.documentElement.style%3B%0A%0Avar%20isFF%20%3D%20!!navigator.userAgent.match(%2Ffirefox%2Fi)%3B%0A” message=”css code” highlight=”” provider=”manual”/]Media Query Hacks
- This is gonna work on, Firefox 3.6 and Later
- Using -engine specific rules ensures effective browser targeting.
- you can use this:
Firefox 2 :
[pastacode lang=”css” manual=”html%3E%2F**%2Fbody%20.selector%2C%20x%3A-moz-any-link%20%0A%7B%0A%20%20color%3Alime%3B%0A%7D%0A” message=”css code” highlight=”” provider=”manual”/]Firefox 3 :
[pastacode lang=”css” manual=”html%3E%2F**%2Fbody%20.selector%2C%20x%3A-moz-any-link%2C%20x%3Adefault%20%0A%7B%0A%20%20color%3Alime%3B%0A%7D%0A” message=”css code” highlight=”” provider=”manual”/]Any Firefox :
[pastacode lang=”css” manual=”%40-moz-document%20url-prefix()%20%0A%7B%20%0A%20%20.selector%0A%20%7B%0A%20%20%20%20%20color%3Alime%3B%20%20%7D%7D%0A” message=”css code” highlight=”” provider=”manual”/]- The only way to do this is via various CSS hacks, which will make your page much more likely to fail on the next browser updates.
- If anything, it will be LESS safe than using a js-browser sniffer.
