Is there a way to make some CSS rules visible only for Opera (9.5 +)?
相关问题
- Adding a timeout to a render function in ReactJS
-
Why does the box-shadow property not apply to a
- Add animation to jQuery function Interval
- jQuery hover to slide?
- Issue with star rating css
I wrote a jQuery $.support extension for detecting css property support.
http://gist.github.com/556448
Additionally i wrote a little snippet to make really little vendor hacks:
This results for example in:
In your Stylesheets use it this way:
With pure CSS hack you might be unable to safely limit upper version you're hacking (e.g.
-o-prefocus
may be supported long after your hack stops fixing things and starts breaking them).and in CSS:
But please double-check CSS spec first to ensure that what you're hacking is actually a bug. Opera 10 has full CSS2.1 support and passes all Acid tests, so if something doesn't appear right, it might be because of other reasons (error somewhere else in the code, detail or corner case you shouldn't rely on, etc.)
The only way I can think of is to check the user agent and only reference the style sheet when it's an opera browser. Since the user agent can be messed with this might not be 100% reliable.
Opera12
Not in any way I would recommend.
Check for Javascript or PHP browser sniffers on Google. Some may be so outdated that you need to add detection for Opera 9.5+, however.
Browser sniffers (for styling) are generally bad practice.
Also, note that Opera 9.5+ gives users the option of masking their browser as IE, rendering any kind of sniffing useless.
Edit: As you can see in another answer, there is
window.opera.version()
. I didn't know thewindow.opera
object contained this information. HOWEVER, you should probably look to see if this object is still available when someone has set Opera to be seen as IE or some other browser.This hack works for the latest Opera:
It doesn't touch any other browser as far as i tested, but this may be actual for several months, with web technologies boom etc.