Using conditional comments it is easy to target Internet Explorer with browser-specific CSS rules:
<!--[if IE 6]>
...include IE6-specific stylesheet here...
<![endif]-->
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.
Note: I'm looking for a 'clean' solution. Using a JavaScript browser sniffer to add a 'firefox' class to my HTML does not qualify as clean in my opinion. I would rather like to see something that depends on browser capabilities, much like conditional comments are only 'special' to IE…
A variation on your idea is to have a
server-side USER-AGENT detector
that will figure out what style sheet to attach to the page. This way you can have afirefox.css, ie.css, opera.css, etc
.You can accomplish a similar thing in Javascript itself, although you may not regard it as clean.
I have done a similar thing by having a
default.css
which includesall common styles and then specific style sheets
are added to override, or enhance the defaults.Updated(from @Antoine comment)
You can use
@supports
More on
@supports
hereThe 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.
OK, I've found it. 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. There's a whole list for these CSS extensions right here: Mozilla CSS Extensions.
Here is some browser hacks for targeting only the Firefox browser,
Using selector hacks.
JavaScript Hacks
Media Query Hacks
This is gonna work on, Firefox 3.6 and Later
If you need more information,Please visit browserhacks
Using -engine specific rules ensures effective browser targeting.