Applying CSS to Opera only
080815
[Edit: 080828] This hack targets only Opera 9 and below, but fails in (at least) v9.52. You should not use it unless you're specifically targeting Opera 9 and below.
If you ever need to apply certain styles to Opera only, there is an easy way that I found in Jeff Starr's post, 'CSS Hack Dumpster'. All you need to do is prefix your selector with html:first-child
.
For example, let's see how you would add a left margin of 10px to all paragraphs in all browsers except Opera:
p {
margin-left: 10px;
}
html:first-child p {
margin-left: 0;
}
This hacks validates and seems reasonably safe. As always, it's a risk to use hacks in your CSS (what would happen if, say, Internet Explorer 12 matched html:first-child? Any websites using this hack wouldn't work correctly in IE12). I'm still going to use it though, it seems quite safe to me.
html:first-child selector also applies to Mozilla based browsers
Are you sure? I don't think so. If you've tested it, can you tell me what version and OS are you using?
But: I recently upgraded Opera to v9.52 and here html:first-child doesn't seem to have any effect. So I'll have to look for another Opera hack. I'll update this post as soon as I get a chance to have a look at this.
You're right.. my bad. I tested it again with Firefox 3 on XP and
Vista - didn't work. And it doesn't seem to work in Opera 9.51
either. One Opera hack I've been using is: @media all and
(min-width: 0px){ selector{property: value;} } Works with recent
versions of Opera
This effects IE too...
I don't think so, which version of IE? I've tried 7, 6 and 5.5, and it doesn't affect any of those.
But I insist: this technique is not useful anymore, because it won't work in newer versions of Opera. Which proves that using hacks is dangerous and should be avoided as much as possible. :)
thanks hakukoneoptimointi, the hack works on Opera 10.52
Hakukoneoptimointi's hack unfortunately does not work in Opera 11.
A.