Make CSS Apply Only for Opera 11

Make CSS apply only for Opera 11?

body {background:0} /* default */
@media not screen and (1) {
body {background:red} /* OP 11 */
}
@media not screen and (orientation) {
body {background:green} /* for the earlier versions of Opera that pick the first media query's rule + chrome/safari */
}

Browsers tested:

  • red: Opera 11
  • green: Opera 10 and 10.5 + WebKit browsers
  • none: Opera 9.26 + Firefox 3.6 + IE9

It's related to the error-handling and also the fact that NOT negates the global result (WebKit browsers don't evaluate orientation correctly without a valid value). Since orientation is supported in presto 2.7 the second media query is FALSE.

The false orientation hack sounds like a good name to me.

How to make CSS visible only for Opera

This hack works for the latest Opera:

 @media all and (-webkit-min-device-pixel-ratio:10000), not all and (-webkit-min-device-pixel-ratio:0) {
#id {css rule}
}

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.

Unable to apply specific CSS only for opera 40.0

Since no hack is available based solely on CSS, the javascript browser detection worked for me and then I used jquery to override the css like this:-

var isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;

if(isOpera){
$(selector).css('margin-top','-30px');
}

How to do a Chrome/Opera specific stylesheet?

A clean JavaScript way to do this: http://rafael.adm.br/css_browser_selector/

It ads browser specific classes to the body tag of your HTML which you can use in your CSS like:

.opera #thingie, .chrome #thingie {
do: this;
}

CSS specific rule for Opera 12?

Here is an officially recommended hack for Opera (in case everything else fails):

doesnotexist:-o-prefocus, .example {
color: red;
}

http://www.opera.com/docs/specs/presto2.12/css/o-vendor/

via: https://stackoverflow.com/a/4021618

p.s.: notice comment by davehale32, that this hack does not work for IE6. I have no IE6 at my disposal now, so i can't confirm or deny that.

Apply style ONLY on IE

Update 2017

Depending on the environment, conditional comments have been officially deprecated and removed in IE10+.


Original

The simplest way is probably to use an Internet Explorer conditional comment in your HTML:

<!--[if IE]>
<style>
.actual-form table {
width: 100%;
}
</style>
<![endif]-->

There are numerous hacks (e.g. the underscore hack) you can use that will allow you to target only IE within your stylesheet, but it gets very messy if you want to target all versions of IE on all platforms.

If opera - something different in css?

With the conditional-css tool, you can target opera, but engine is important. conditional-css.com explains:

Conditional-CSS isn't really all that interested in which browser the
user is using, but rather what rendering engine the user's browser
utilises. This is why Conditional-CSS uses 'Gecko' rather than the
well known Firefox as one of it's browser conditions. Likewise for
Safari 'Webkit' is used. This allows other browsers using the same
rendering engines to receive the same targeted CSS. An exception to
this rule is made for IE (rather than using 'Trident') since this is
what the IE conditional comments use and Trident isn't particuarly
well known. Similarly for Opera, since only the Opera browser uses
it's Presto rendering engine, 'Opera' is used.

http://www.conditional-css.com/advanced

they write that a conditional tag is formed like:

[if {!} browser]
[if {!} browser version]
[if {!} condition browser version]

and that browser names are as follows:

IE - Internet Explorer
Gecko - Gecko based browsers (Firefox, Camino etc)
Webkit - Webkit based browsers (Safari, Shiira etc)
'SafMob' - Mobile Safari (iPhone / iPod Touch)
Opera - Opera's browser
IEMac - Internet Explorer for the Mac
Konq - Konqueror
IEmob - IE mobile
PSP - Playstation Portable
NetF - Net Front

So it should logically follow, according to them, that you can target via:
[if Opera]

like this in a CSS block:

[if Opera] .box {  
width: 500px;
padding: 100px 0;
}

or like this for a CSS include:

<!--[if Opera]>

<![endif]-->


Related Topics



Leave a reply



Submit